Skip to content

Instantly share code, notes, and snippets.

@majirosstefan
Created September 19, 2021 10:29
Show Gist options
  • Save majirosstefan/6a817139dc3f6f88273aac23f914b8e9 to your computer and use it in GitHub Desktop.
Save majirosstefan/6a817139dc3f6f88273aac23f914b8e9 to your computer and use it in GitHub Desktop.
Booti Android Emulator in CI pipeline, Boot iOS Simulator in CI pipeline, Cavy, E2E tests
#!/usr/bin/env bash
echo "Running E2E tests"
# ( setopt posixbuiltin; set; ) | less | cat
# -n if not null
if [ -n "$APPCENTER_ANDROID_VARIANT" ]; then
echo "Setup Android simulator"
SIMULATOR_IMAGE="system-images;android-28;google_apis;x86"
SIMULATOR_NAME="Pixel_XL_API_28"
ANDROID_HOME=~/Library/Android/sdk
# ANDROID_SDK_ROOT=~/Library/Android/sdk
# ANDROID_AVD_HOME=~/.android/avd
PATH="$ANDROID_HOME/emulator:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH"
echo "Accepts all sdk licences"
yes | sdkmanager --licenses
# touch /Users/runner/.android/repositories.cfg
echo "Download Simulator Image"
sdkmanager --install "$SIMULATOR_IMAGE"
echo "Create Simulator '$SIMULATOR_NAME' with image '$SIMULATOR_IMAGE'"
echo "no" | avdmanager --verbose create avd --force --name "$SIMULATOR_NAME" --device "pixel" --package "$SIMULATOR_IMAGE" --tag "google_apis" --abi "x86"
# echo no | /Users/runner/Library/Android/sdk/tools/bin/avdmanager create avd -n "$SIMULATOR_NAME" -d pixel --package "$SIMULATOR_IMAGE"
# emulator -list-avds
emulator -avd "$SIMULATOR_NAME" -no-snapshot -no-snapshot-load -verbose -noaudio -wipe-data -no-window -gpu swiftshader_indirect &
#Start the emulator
EMULATOR_PID=$!
# wait until emulator starts
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 until emulator is booted..."
sleep 1
done
# debug for analytics
adb shell setprop debug.firebase.analytics.app org.stefanmajiros.bluepass
adb shell setprop log.tag.FA VERBOSE
# Unlock the Lock Screen
$ANDROID_HOME/platform-tools/adb shell input keyevent 82
# Clear and capture logcat, before running tests
echo "Capturing logcat"
$ANDROID_HOME/platform-tools/adb logcat -c
$ANDROID_HOME/platform-tools/adb logcat >./logcat.log &
LOGCAT_PID=$!
echo "Running Android E2E tests"
npm run e2e:android
if [ $? -eq 0 ]; then
echo "e2e SUCCESS"
# Stop the background processes
kill $LOGCAT_PID
kill $EMULATOR_PID
return 0
else
echo "e2e ERROR"
kill $LOGCAT_PID
kill $EMULATOR_PID
return 1
fi
else
GRACE_TIME=80
echo "Setup iOS Simulator"
echo "Installing iOS Simulator dependencies"
brew tap wix/brew
brew update
brew install applesimutils
echo "Installing pods"
cd ./ios && /usr/local/lib/ruby/gems/2.7.0/bin/pod install --repo-update && cd ..
SIMULATOR_ID=$(xcrun simctl create My-iphone12 com.apple.CoreSimulator.SimDeviceType.iPhone-12 com.apple.CoreSimulator.SimRuntime.iOS-14-4)
echo "Running $SIMULATOR_ID"
echo "Booting simulator $SIMULATOR_ID"
xcrun simctl boot "$SIMULATOR_ID"
echo "Waiting ${GRACE_TIME}s to let it boot the new simulator"
for i in $(seq 1 $GRACE_TIME); do echo -n '.'; sleep 1; done; echo " OK."
echo "Starting logging service"
xcrun simctl spawn booted log stream --debug --predicate 'subsystem == "org.stefanmajiros.bluepass.prod"' > deviceLog.log &
# echo application logs from React Native to separate file
xcrun simctl spawn booted log stream --debug --predicate 'subsystem == "com.facebook.react.log"' > reactLog.log &
echo "Starting E2E tests"
npm run e2e:ios -- --udid "$SIMULATOR_ID"
xcrun simctl shutdown booted
xcrun simctl delete "$SIMULATOR_ID"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment