Skip to content

Instantly share code, notes, and snippets.

@dominicthomas
Created July 4, 2018 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dominicthomas/767b1c7eb19d303f622c191bd105394e to your computer and use it in GitHub Desktop.
Save dominicthomas/767b1c7eb19d303f622c191bd105394e to your computer and use it in GitHub Desktop.
Script that could be used to prepare and run ui tests
#!/bin/bash
EMULATOR_NAME=$1
USER_NAME=$2
ENVIRONMENT=$3
# Start an emulator
${ANDROID_HOME}/tools/emulator -avd ${EMULATOR_NAME} -wipe-data &
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
# Disable animations
${ANDROID_HOME}/platform-tools/adb shell settings put global window_animation_scale 0.0
${ANDROID_HOME}/platform-tools/adb shell settings put global transition_animation_scale 0.0
${ANDROID_HOME}/platform-tools/adb shell settings put global animator_duration_scale 0.0
# Unlock the Lock Screen
#$ANDROID_HOME/platform-tools/adb shell input keyevent 82
# 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 and open report if there is a failure
if ! ./gradlew :<app-name>:connectedAndroidTest -i -Porchestrator=true ; then
open <app-name>/build/reports/androidTests/connected/flavors/<flavour>/index.html
fi
# Stop the background processes
kill ${LOGCAT_PID}
kill ${EMULATOR_PID}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment