Skip to content

Commit b267665

Browse files
test: Use Appium2 to run functional tests (appium#723)
1 parent d4c44b4 commit b267665

22 files changed

Lines changed: 144 additions & 106 deletions

.pre-commit-config.yaml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
- repo: https://github.com/pre-commit/mirrors-isort
2-
rev: v4.3.21
1+
repos:
2+
- repo: https://github.com/pre-commit/mirrors-isort
3+
rev: v5.10
34
hooks:
4-
- id: isort
5-
args: ["."]
6-
- repo: https://github.com/pre-commit/mirrors-mypy
7-
rev: 'v0.800'
5+
- id: isort
6+
args: [ "." ]
7+
- repo: https://github.com/pre-commit/mirrors-mypy
8+
rev: v0.961
89
hooks:
9-
- id: mypy
10+
- id: mypy
1011
entry: mypy appium/ test/functional
1112
pass_filenames: false
12-
- repo: https://github.com/psf/black
13-
rev: 20.8b1
13+
- repo: https://github.com/psf/black
14+
rev: 22.3.0
1415
hooks:
15-
- id: black
16-
args: [".", "-l", "120", "-S"]
16+
- id: black
17+
args: [ ".", "-l", "120", "-S" ]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ $ pytest test/functional/ios/search_context/find_by_ios_class_chain_tests.py
235235

236236
#### In parallel for iOS
237237

238-
1. Create simulators named 'iPhone 8 - 8100' and 'iPhone 8 - 8101'
238+
1. Create simulators named 'iPhone X - 8100' and 'iPhone X - 8101'
239239
2. Install test libraries via pip, `pip install pytest pytest-xdist`
240240
3. Run tests
241241

azure-pipelines.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,3 @@ jobs:
3333
inputs:
3434
testResultsFiles: '**/junit.xml'
3535
testRunTitle: 'Publish test results for Python $(python.version)'
36-
37-
# Runs tests nightly to make sure they works against appium@beta
38-
schedules:
39-
- cron: "0 0 * * *"
40-
displayName: Daily Nightly build (UTC)
41-
branches:
42-
include:
43-
- master
44-
always: true

ci-jobs/functional/run_android_test.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,23 @@ jobs:
44
vmImage: ${{ parameters.vmImage }}
55
variables:
66
ANDROID_SDK_VERSION: ${{ parameters.sdkVer }}
7+
ANDROID_AVD: testemulator
78
CI: ${{ parameters.ci }}
89
steps:
9-
- template: ./run_appium.yml
10-
parameters:
11-
OPENCV: ${{ parameters.opencv }}
12-
DONT_RUN_APPIUM: ${{ parameters.dont_run_appium }}
10+
- template: ./setup_appium.yml
11+
- script: appium driver install uiautomator2
12+
displayName: Install UIAutomator2 driver
1313
- script: bash ci-jobs/functional/start-emulator.sh
1414
displayName: Create and run Emulator
1515
- script: |
16+
if [[ '${{ parameters.dontRunAppium }}' != true ]]; then
17+
appium --relaxed-security > appium_log.txt 2>&1 &
18+
sleep 2
19+
fi
20+
pushd "$(pwd)"
1621
cd test/functional/android
1722
python -m pytest ${{ parameters.testFiles}} ${{ parameters.pytestOpt }}
23+
popd
1824
displayName: Run Android functional tests
1925
- template: ./publish_test_result.yml
2026
- template: ./save_appium_log.yml

ci-jobs/functional/run_ios_test.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@ jobs:
55
variables:
66
CI: ${{ parameters.ci }}
77
steps:
8-
- template: ./run_appium.yml
8+
- template: ./setup_appium.yml
99
- template: ./ios_setup.yml
1010
parameters:
1111
xcodeVersion: ${{ parameters.xcodeForIOS }}
12+
- script: appium driver install xcuitest
13+
displayName: Install XCUITest driver
1214
- script: |
15+
if [[ '${{ parameters.dontRunAppium }}' != true ]]; then
16+
appium --relaxed-security > appium_log.txt 2>&1 &
17+
sleep 2
18+
fi
19+
pushd "$(pwd)"
1320
cd test/functional/ios
1421
python -m pytest ${{ parameters.testFiles}} ${{ parameters.pytestOpt }}
22+
popd
1523
displayName: Run iOS functional tests
1624
- template: ./publish_test_result.yml
1725
- template: ./save_appium_log.yml
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
steps:
22
- task: NodeTool@0
33
inputs:
4-
versionSpec: '12.x'
5-
displayName: Install Node 12.x
6-
- script: npm install -g appium@beta --chromedriver_version='2.44'
4+
versionSpec: '16.x'
5+
displayName: Install Node 16.x
6+
- script: npm install -g appium@next --chromedriver_version='2.44'
77
displayName: Install appium
8-
- script: npm install -g opencv4nodejs
9-
condition: eq('${{ parameters.opencv }}', true)
10-
displayName: Install opencv4nodejs
118
- task: UsePythonVersion@0
129
inputs:
1310
versionSpec: '3.x'
@@ -29,6 +26,3 @@ steps:
2926
appium --version
3027
node --version
3128
displayName: Check versions
32-
- script: nohup appium --relaxed-security > appium_log.txt &
33-
condition: ne('${{ parameters.dont_run_appium }}', true)
34-
displayName: Run Appium in background
Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/usr/bin/env bash
22

3-
# This file comes from https://github.com/appium/ruby_lib_core
4-
53
# 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
64
# with some changes
75

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

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

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

2018
echo "Starting emulator"
2119

2220
# Start emulator in background
23-
nohup ${ANDROID_HOME}/emulator/emulator -avd testemulator -no-boot-anim -no-snapshot > /dev/null 2>&1 &
24-
${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'
25-
26-
${ANDROID_HOME}/platform-tools/adb devices
27-
28-
echo "Emulator started"
21+
nohup $ANDROID_HOME/emulator/emulator -avd $ANDROID_AVD -no-snapshot > /dev/null 2>&1 &
22+
23+
adb wait-for-device get-serialno
24+
secondsStarted=`date +%s`
25+
TIMEOUT=360
26+
while [[ $(( `date +%s` - $secondsStarted )) -lt $TIMEOUT ]]; do
27+
# Fail fast if Emulator process crashed
28+
pgrep -nf avd || exit 1
29+
30+
pstat=$(adb shell ps)
31+
if ! [[ $pstat =~ "root " ]]; then
32+
# In recent APIs running `ps` without `-A` only returns
33+
# processes belonging to the current user (in this case `shell`)
34+
pstat=$(adb shell ps -A)
35+
fi
36+
37+
if [[ $pstat =~ "com.android.systemui" ]]; then
38+
echo "System UI process is running. Checking services availability"
39+
if adb shell "ime list && pm get-install-location && echo PASS" | grep -q "PASS"; then
40+
break
41+
fi
42+
fi
43+
44+
sleep 5
45+
secondsElapsed=$(( `date +%s` - $secondsStarted ))
46+
secondsLeft=$(( $TIMEOUT - $secondsElapsed ))
47+
echo "Waiting until emulator finishes services startup; ${secondsElapsed}s elapsed; ${secondsLeft}s left"
48+
done
49+
50+
bootDuration=$(( `date +%s` - $secondsStarted ))
51+
if [[ $bootDuration -ge $TIMEOUT ]]; then
52+
echo "Emulator has failed to fully start within ${TIMEOUT}s"
53+
exit 1
54+
fi
55+
echo "Emulator booting took ${bootDuration}s"
56+
adb shell input keyevent 82
57+
58+
adb devices -l

ci-jobs/functional_test.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
parameters:
2-
vmImage: 'macOS-10.15'
2+
vmImage: 'macOS-12'
33
pytestOpt: '--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html'
44
androidSdkVer: 27
5-
xcodeForIOS: 12.3
5+
xcodeForIOS: 13.4
66
CI: true
77

88
jobs:
@@ -30,7 +30,6 @@ jobs:
3030
testFiles: 'device_time_tests.py search_context/find_by_*.py'
3131
sdkVer: ${{ parameters.androidSdkVer }}
3232
CI: ${{ parameters.ci }}
33-
OPENCV: true
3433
- template: ./functional/run_android_test.yml
3534
parameters:
3635
name: 'func_test_android2'
@@ -47,7 +46,7 @@ jobs:
4746
testFiles: 'appium_service_tests.py'
4847
sdkVer: ${{ parameters.androidSdkVer }}
4948
CI: ${{ parameters.ci }}
50-
DONT_RUN_APPIUM: true
49+
dontRunAppium: true
5150
- template: ./functional/run_android_test.yml
5251
parameters:
5352
name: 'func_test_android4'

test/functional/android/chrome_tests.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
# limitations under the License.
1414

1515
from appium import webdriver
16+
from appium.options.common import AppiumOptions
1617
from appium.webdriver.common.appiumby import AppiumBy
18+
from test.helpers.constants import SERVER_URL_BASE
1719

1820
from .helper.desired_capabilities import get_desired_capabilities
1921

@@ -22,13 +24,13 @@ class TestChrome(object):
2224
def setup_method(self) -> None:
2325
caps = get_desired_capabilities()
2426
caps['browserName'] = 'Chrome'
25-
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', caps)
27+
self.driver = webdriver.Remote(SERVER_URL_BASE, options=AppiumOptions().load_capabilities(caps))
2628

2729
def teardown_method(self) -> None:
2830
self.driver.quit()
2931

3032
def test_find_single_element(self) -> None:
31-
self.driver.get('http://10.0.2.2:4723/test/guinea-pig')
33+
self.driver.get(f'{SERVER_URL_BASE}/test/guinea-pig')
3234
self.driver.find_element(by=AppiumBy.LINK_TEXT, value='i am a link').click()
3335

3436
assert 'I am some other page content' in self.driver.page_source

test/functional/android/context_switching_tests.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@
1616

1717
from appium import webdriver
1818
from appium.common.exceptions import NoSuchContextException
19+
from appium.options.common import AppiumOptions
1920
from appium.webdriver.common.appiumby import AppiumBy
21+
from test.helpers.constants import SERVER_URL_BASE
2022

2123
from .helper import desired_capabilities
2224

2325

2426
@pytest.mark.skip(reason="Need to fix broken test")
2527
class TestContextSwitching(object):
2628
def setup_method(self) -> None:
27-
desired_caps = desired_capabilities.get_desired_capabilities('selendroid-test-app.apk')
28-
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
29+
caps = desired_capabilities.get_desired_capabilities('selendroid-test-app.apk')
30+
self.driver = webdriver.Remote(SERVER_URL_BASE, options=AppiumOptions().load_capabilities(caps))
2931

3032
def teardown_method(self) -> None:
3133
self.driver.quit()

0 commit comments

Comments
 (0)