Skip to content

Instantly share code, notes, and snippets.

@Yazazzello
Created February 21, 2018 08:42
Show Gist options
  • Save Yazazzello/77d9b8ca720dcefc08f2e64032f6acc1 to your computer and use it in GitHub Desktop.
Save Yazazzello/77d9b8ca720dcefc08f2e64032f6acc1 to your computer and use it in GitHub Desktop.
script for sequentially running espresso test on headless android emulators
#!/bin/bash
#emulators=( "$@" )
#usage bash smoketests $ARRAY_OF_AVD_IDS
emulators=(
#"Nexus_5_API_24"
#"Nexus_S_API_23"
#"Nexus_5_API_25"
#"Nexus_5_API_26"
#"Nexus_5_API_19"
#"Nexus_5_API_22"
#"Nexus_5_API_27"
#"Nexus_5_API_17"
#"Nexus_5_API_18"
)
for emulator in "${emulators[@]}"
do
echo "emulator name ${emulator}"
#Start the emulator
${ANDROID_HOME}/tools/emulator -avd ${emulator} -no-audio -no-window & EMULATOR_PID=$!
# Wait for Android to finish booting
WAIT_CMD="${ANDROID_HOME}/platform-tools/adb wait-for-device shell getprop init.svc.bootanim"
until ${WAIT_CMD} | grep -m 1 stopped; do
echo "Waiting..."
sleep 1
done
# Unlock the Lock Screen
${ANDROID_HOME}/platform-tools/adb shell input keyevent 82
# Uninstall app
${ANDROID_HOME}/platform-tools/adb uninstall $PACKAGE_ID
# Clear and capture logcat
${ANDROID_HOME}/platform-tools/adb logcat -c
${ANDROID_HOME}/platform-tools/adb logcat > build/logcat.log & LOGCAT_PID=$!
# Run the tests
./gradlew app:connectedAndroidTest -x app:lintDebug -Pandroid.testInstrumentationRunnerArguments.class=$SMOKE_TEST_CLASS; gradlew_return_code=$?
echo "gradle exit code ${gradlew_return_code}"
# Stop the background processes
kill -9 ${LOGCAT_PID}
kill -9 ${EMULATOR_PID}
if [ ${gradlew_return_code} -ne 0 ]
then
echo "smoke test was failed on ${emulator}, exiting..."
exit 1
fi
done
@sohailshaikh001
Copy link

sohailshaikh001 commented Oct 30, 2019

Can we run this script with Jenkins?
I want to run espresso test with the Jenkins on mac mini, will this script work for me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment