Sitelet https://github.com/appium/python-client/pull/723/commits/a002488c88a91c192fa0d8c7cc07ae2bd1b660ef
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update emulator script
  • Loading branch information
mykola-mokhnach committed Jun 13, 2022
commit a002488c88a91c192fa0d8c7cc07ae2bd1b660ef
1 change: 1 addition & 0 deletions ci-jobs/functional/run_android_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ jobs:
vmImage: ${{ parameters.vmImage }}
variables:
ANDROID_SDK_VERSION: ${{ parameters.sdkVer }}
ANDROID_AVD: testemulator
CI: ${{ parameters.ci }}
steps:
- template: ./setup_appium.yml
Expand Down
48 changes: 39 additions & 9 deletions ci-jobs/functional/start-emulator.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env bash

# This file comes from https://github.com/appium/ruby_lib_core

# This script was copy-pasted from https://docs.microsoft.com/en-us/azure/devops/pipelines/languages/android?view=azure-devops#test-on-the-android-emulator
# with some changes

Expand All @@ -13,16 +11,48 @@ echo "y" | ${ANDROID_HOME}/tools/bin/sdkmanager --install "$emulator"
${ANDROID_HOME}/tools/bin/avdmanager list

# Create emulator
echo "no" | ${ANDROID_HOME}/tools/bin/avdmanager create avd -d "Nexus 6" -n testemulator -k "${emulator}" --force
echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd -d "Nexus 6" -n $ANDROID_AVD -k "$emulator" -c 1500M --force

echo ${ANDROID_HOME}/emulator/emulator -list-avds

echo "Starting emulator"

# Start emulator in background
nohup ${ANDROID_HOME}/emulator/emulator -avd testemulator -no-boot-anim -no-snapshot > /dev/null 2>&1 &
${ANDROID_HOME}/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 1; done; input keyevent 82'

${ANDROID_HOME}/platform-tools/adb devices

echo "Emulator started"
nohup $ANDROID_HOME/emulator/emulator -avd $ANDROID_AVD -no-snapshot > /dev/null 2>&1 &

adb wait-for-device get-serialno
secondsStarted=`date +%s`
TIMEOUT=360
while [[ $(( `date +%s` - $secondsStarted )) -lt $TIMEOUT ]]; do
# Fail fast if Emulator process crashed
pgrep -nf avd || exit 1

pstat=$(adb shell ps)
if ! [[ $pstat =~ "root " ]]; then
# In recent APIs running `ps` without `-A` only returns
# processes belonging to the current user (in this case `shell`)
pstat=$(adb shell ps -A)
fi

if [[ $pstat =~ "com.android.systemui" ]]; then
echo "System UI process is running. Checking services availability"
if adb shell "ime list && pm get-install-location && echo PASS" | grep -q "PASS"; then
break
fi
fi

sleep 5
secondsElapsed=$(( `date +%s` - $secondsStarted ))
secondsLeft=$(( $TIMEOUT - $secondsElapsed ))
echo "Waiting until emulator finishes services startup; ${secondsElapsed}s elapsed; ${secondsLeft}s left"
done

bootDuration=$(( `date +%s` - $secondsStarted ))
if [[ $bootDuration -ge $TIMEOUT ]]; then
echo "Emulator has failed to fully start within ${TIMEOUT}s"
exit 1
fi
echo "Emulator booting took ${bootDuration}s"
adb shell input keyevent 82

adb devices -l
2 changes: 1 addition & 1 deletion test/unit/helper/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def appium_command(command: str) -> str:
Returns:
str: A string of command URL
"""
return f'{SERVER_URL_BASE}{command}'
return f'{SERVER_URL_BASE}{command}' if SERVER_URL_BASE.endswith('/') else f'{SERVER_URL_BASE}/{command}'


def android_w3c_driver() -> 'WebDriver':
Expand Down