I am testing hybrid application for the automation and on launch it shows the very first screen as Native and then clicking on the button on that screen it opens the Webview. At this point I can see both Native and Webview Contexts but after doing some operations when I click on the button then it redirects to the Native screen. Now when I am trying to get the available Contexts it only shows the Native one only not the Webview one, which is causing my test case failed.
Please note that I always get bot the Contexts when I launch the app but post that I only get the Native Context. I tried changing multiple devices but same issue.
Logs for reference from my Device farm test execution:
[DEVICEFARM] Setting up your device. This usually takes 2-3 minutes.
[DEVICEFARM] ########### Start executing testspec ###########
[DEVICEFARM] ########### Entering phase install ###########
[DeviceFarm] devicefarm-cli use node 18
[DeviceFarm] node --version
v18.16.1
[DeviceFarm] export NVM_DIR=$HOME/.nvm
[DeviceFarm] . $NVM_DIR/nvm.sh
/tmp/devicefarm-workspace/execution-j27rfca7/shell-script-rfg48wvd/shell_script.sh: line 30: /home/device-farm/.nvm/nvm.sh: No such file or directory
[DeviceFarm] nvm install --lts
/tmp/devicefarm-workspace/execution-j27rfca7/shell-script-rfg48wvd/shell_script.sh: line 32: nvm: command not found
[DeviceFarm] devicefarm-cli use appium 2
[DeviceFarm] appium --version
dbug Appium Parsed manifest file at /home/device-farm/.appium/node_modules/.cache/appium/extensions.yaml: {
dbug Appium "drivers": {
dbug Appium "uiautomator2": {
dbug Appium "automationName": "UiAutomator2",
dbug Appium "platformNames": [
dbug Appium "Android"
dbug Appium ],
dbug Appium "mainClass": "AndroidUiautomator2Driver",
dbug Appium "scripts": {
dbug Appium "reset": "scripts/reset.js"
dbug Appium },
dbug Appium "doctor": {
dbug Appium "checks": [
dbug Appium "./build/lib/doctor/required-checks.js",
dbug Appium "./build/lib/doctor/optional-checks.js"
dbug Appium ]
dbug Appium },
dbug Appium "pkgName": "appium-uiautomator2-driver",
dbug Appium "version": "2.44.0",
dbug Appium "appiumVersion": "^2.4.1",
dbug Appium "installType": "npm",
dbug Appium "installSpec": "appium-uiautomator2-driver@2.44.0",
dbug Appium "installPath": "/home/device-farm/.appium/node_modules/appium-uiautomator2-driver"
dbug Appium }
dbug Appium },
dbug Appium "plugins": {},
dbug Appium "schemaRev": 4
dbug Appium }
2.5.1
[DeviceFarm] export APPIUM_BASE_PATH=/wd/hub
[DeviceFarm] devicefarm-cli use python 3.10
[DeviceFarm] python --version
Python 3.10.12
[DeviceFarm] cd $DEVICEFARM_TEST_PACKAGE_PATH
[DeviceFarm] python -m pip install -r requirements.txt
Defaulting to user installation because normal site-packages is not writeable
Collecting Appium-Python-Client==4.0.1
Downloading appium_python_client-4.0.1.tar.gz (120 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 120.8/120.8 kB 5.4 MB/s eta 0:00:00
Preparing metadata (setup.py): started
Preparing metadata (setup.py): finished with status 'done'
Collecting attrs==23.2.0
Downloading attrs-23.2.0-py3-none-any.whl (60 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 60.8/60.8 kB 15.6 MB/s eta 0:00:00
Collecting certifi==2024.7.4
Downloading certifi-2024.7.4-py3-none-any.whl (162 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 163.0/163.0 kB 13.1 MB/s eta 0:00:00
Collecting charset-normalizer==3.3.2
Downloading charset_normalizer-3.3.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (142 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 142.1/142.1 kB 32.4 MB/s eta 0:00:00
Collecting execnet==2.1.1
Downloading execnet-2.1.1-py3-none-any.whl (40 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 40.6/40.6 kB 9.6 MB/s eta 0:00:00
Collecting Faker==28.4.1
Downloading Faker-28.4.1-py3-none-any.whl (1.8 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.8/1.8 MB 61.0 MB/s eta 0:00:00
Collecting h11==0.14.0
Downloading h11-0.14.0-py3-none-any.whl (58 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 58.3/58.3 kB 14.2 MB/s eta 0:00:00
Collecting idna==3.7
Downloading idna-3.7-py3-none-any.whl (66 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 66.8/66.8 kB 16.6 MB/s eta 0:00:00
Collecting iniconfig==2.0.0
Downloading iniconfig-2.0.0-py3-none-any.whl (5.9 kB)
Collecting Jinja2==3.1.4
Downloading jinja2-3.1.4-py3-none-any.whl (133 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 133.3/133.3 kB 29.8 MB/s eta 0:00:00
Collecting jsonpath-ng==1.6.1
Downloading jsonpath_ng-1.6.1-py3-none-any.whl (29 kB)
Collecting MarkupSafe==2.1.5
Downloading MarkupSafe-2.1.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25 kB)
Collecting outcome==1.3.0.post0
Downloading outcome-1.3.0.post0-py2.py3-none-any.whl (10 kB)
Collecting packaging==24.1
Downloading packaging-24.1-py3-none-any.whl (53 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 54.0/54.0 kB 13.4 MB/s eta 0:00:00
Collecting pluggy==1.5.0
Downloading pluggy-1.5.0-py3-none-any.whl (20 kB)
Collecting ply==3.11
Downloading ply-3.11-py2.py3-none-any.whl (49 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 49.6/49.6 kB 12.2 MB/s eta 0:00:00
Collecting PySocks==1.7.1
Downloading PySocks-1.7.1-py3-none-any.whl (16 kB)
Collecting pytest==8.2.2
Downloading pytest-8.2.2-py3-none-any.whl (339 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 339.9/339.9 kB 49.2 MB/s eta 0:00:00
Collecting pytest-check==2.4.1
Downloading pytest_check-2.4.1-py3-none-any.whl (13 kB)
Collecting pytest-html==4.1.1
Downloading pytest_html-4.1.1-py3-none-any.whl (23 kB)
Collecting pytest-metadata==3.1.1
Downloading pytest_metadata-3.1.1-py3-none-any.whl (11 kB)
Collecting pytest-order==1.3.0
Downloading pytest_order-1.3.0-py3-none-any.whl (14 kB)
Collecting pytest-xdist==3.6.1
Downloading pytest_xdist-3.6.1-py3-none-any.whl (46 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 46.1/46.1 kB 12.1 MB/s eta 0:00:00
Collecting python-dateutil==2.9.0.post0
Downloading python_dateutil-2.9.0.post0-py2.py3-none-any.whl (229 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 229.9/229.9 kB 41.6 MB/s eta 0:00:00
Collecting pytz==2024.2
Downloading pytz-2024.2-py2.py3-none-any.whl (508 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 508.0/508.0 kB 74.8 MB/s eta 0:00:00
Collecting requests==2.32.3
Downloading requests-2.32.3-py3-none-any.whl (64 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 64.9/64.9 kB 15.6 MB/s eta 0:00:00
Collecting selenium==4.22.0
Downloading selenium-4.22.0-py3-none-any.whl (9.4 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 9.4/9.4 MB 130.3 MB/s eta 0:00:00
Collecting six==1.16.0
Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting sniffio==1.3.1
Downloading sniffio-1.3.1-py3-none-any.whl (10 kB)
Collecting sortedcontainers==2.4.0
Downloading sortedcontainers-2.4.0-py2.py3-none-any.whl (29 kB)
Collecting trio==0.26.0
Downloading trio-0.26.0-py3-none-any.whl (475 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 475.7/475.7 kB 93.6 MB/s eta 0:00:00
Collecting trio-websocket==0.11.1
Downloading trio_websocket-0.11.1-py3-none-any.whl (17 kB)
Collecting typing_extensions==4.12.2
Downloading typing_extensions-4.12.2-py3-none-any.whl (37 kB)
Collecting u-msgpack-python==2.8.0
Downloading u_msgpack_python-2.8.0-py2.py3-none-any.whl (10 kB)
Collecting urllib3==2.2.2
Downloading urllib3-2.2.2-py3-none-any.whl (121 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 121.4/121.4 kB 46.5 MB/s eta 0:00:00
Collecting websocket-client==1.8.0
Downloading websocket_client-1.8.0-py3-none-any.whl (58 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 58.8/58.8 kB 21.5 MB/s eta 0:00:00
Collecting wsproto==1.2.0
Downloading wsproto-1.2.0-py3-none-any.whl (24 kB)
Collecting tomli>=1
Downloading tomli-2.2.1-py3-none-any.whl (14 kB)
Collecting exceptiongroup>=1.0.0rc8
Downloading exceptiongroup-1.2.2-py3-none-any.whl (16 kB)
Collecting urllib3[socks]<3,>=1.26
Downloading urllib3-2.2.3-py3-none-any.whl (126 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 126.3/126.3 kB 47.3 MB/s eta 0:00:00
Installing collected packages: u-msgpack-python, sortedcontainers, pytz, ply, websocket-client, urllib3, typing_extensions, tomli, sniffio, six, PySocks, pluggy, packaging, MarkupSafe, jsonpath-ng, iniconfig, idna, h11, execnet, exceptiongroup, charset-normalizer, certifi, attrs, wsproto, requests, python-dateutil, pytest, outcome, Jinja2, trio, pytest-xdist, pytest-order, pytest-metadata, pytest-check, Faker, trio-websocket, pytest-html, selenium, Appium-Python-Client
DEPRECATION: Appium-Python-Client is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
Running setup.py install for Appium-Python-Client: started
Running setup.py install for Appium-Python-Client: finished with status 'done'
Successfully installed Appium-Python-Client-4.0.1 Faker-28.4.1 Jinja2-3.1.4 MarkupSafe-2.1.5 PySocks-1.7.1 attrs-23.2.0 certifi-2024.7.4 charset-normalizer-3.3.2 exceptiongroup-1.2.2 execnet-2.1.1 h11-0.14.0 idna-3.7 iniconfig-2.0.0 jsonpath-ng-1.6.1 outcome-1.3.0.post0 packaging-24.1 pluggy-1.5.0 ply-3.11 pytest-8.2.2 pytest-check-2.4.1 pytest-html-4.1.1 pytest-metadata-3.1.1 pytest-order-1.3.0 pytest-xdist-3.6.1 python-dateutil-2.9.0.post0 pytz-2024.2 requests-2.32.3 selenium-4.22.0 six-1.16.0 sniffio-1.3.1 sortedcontainers-2.4.0 tomli-2.2.1 trio-0.26.0 trio-websocket-0.11.1 typing_extensions-4.12.2 u-msgpack-python-2.8.0 urllib3-2.2.2 websocket-client-1.8.0 wsproto-1.2.0
[notice] A new release of pip is available: 23.0.1 -> 24.3.1
[notice] To update, run: python -m pip install --upgrade pip
[DEVICEFARM] ########### Entering phase pre_test ###########
[DeviceFarm] appium --base-path=$APPIUM_BASE_PATH --log-timestamp
--log-no-colors --relaxed-security --default-capabilities
"{"appium:deviceName": "$DEVICEFARM_DEVICE_NAME",
"platformName": "$DEVICEFARM_DEVICE_PLATFORM_NAME",
"appium:app": "$DEVICEFARM_APP_PATH",
"appium:udid":"$DEVICEFARM_DEVICE_UDID",
"appium:platformVersion": "$DEVICEFARM_DEVICE_OS_VERSION",
"appium:chromedriverExecutableDir": "$DEVICEFARM_CHROMEDRIVER_EXECUTABLE_DIR",
"appium:automationName": "UiAutomator2"}" \
$DEVICEFARM_LOG_DIR/appium.log 2>&1 &
[DeviceFarm] appium_initialization_time=0;
until curl --silent --fail "http://0.0.0.0:4723${APPIUM_BASE_PATH}/status"; do
if [[ $appium_initialization_time -gt 30 ]]; then
echo "Appium did not start within 30 seconds. Exiting...";
exit 1;
fi;
appium_initialization_time=$((appium_initialization_time + 1));
echo "Waiting for Appium to start on port 4723...";
sleep 1;
done;
Waiting for Appium to start on port 4723...
{"value":{"ready":true,"message":"The server is ready to accept new connections","build":{"version":"2.5.1"}}}
[DEVICEFARM] ########### Entering phase test ###########
[DeviceFarm] cd $DEVICEFARM_TEST_PACKAGE_PATH
[DeviceFarm] echo "Starting the Appium Python test"
Starting the Appium Python test
[DeviceFarm] python -m pytest -m onboarding tests/ --platform="android" --env="qa" --target="remote" --lang="en" --junit-xml $DEVICEFARM_LOG_DIR/junitreport.xml
============================= test session starts ==============================
platform linux -- Python 3.10.12, pytest-8.2.2, pluggy-1.5.0
rootdir: /tmp/devicefarm-workspace/execution-j27rfca7/test-package-hod9ciss
configfile: pytest.ini
plugins: xdist-3.6.1, order-1.3.0, metadata-3.1.1, check-2.4.1, Faker-28.4.1, html-4.1.1
collected 27 items / 19 deselected / 8 selected
tests/onboarding/test_onboarding.py::TestOnboarding::test_user_onboarding_with_valid_details
-------------------------------- live log setup --------------------------------
12-12-2024 05:00:24 AM Thu -[conftest.py:102 - setup_driver() ] - INFO : ********** Test Case [test_user_onboarding_with_valid_details] Started **********
12-12-2024 05:00:41 AM Thu -[driverfactory.py:46 - get_driver() ] - INFO : ********* Appium Driver Started For ANDROID *********
12-12-2024 05:00:43 AM Thu -[basepage.py:56 - click_element() ] - INFO : Clicked on element using locator->('id', 'English')
12-12-2024 05:00:44 AM Thu -[basepage.py:56 - click_element() ] - INFO : Clicked on element using locator->('xpath', '//*[@resource-id="language_select_screen_apply_button"]/android.widget.TextView')
12-12-2024 05:01:00 AM Thu -[basepage.py:204 - switch_contexts() ] - INFO : Available Context(s)-> ['NATIVE_APP', 'WEBVIEW_chrome']
12-12-2024 05:01:00 AM Thu -[basepage.py:205 - switch_contexts() ] - INFO : Switched to Context-> WEBVIEW_chrome
12-12-2024 05:01:00 AM Thu -[basepage.py:106 - get_element_text() ] - INFO : Element text fetched-> Mobile App 1.0.0-159-qa Chrome 131.0.0.0 12/12/2024 12:00 AM EST using locator->('css selector', '.system-info')
12-12-2024 05:01:03 AM Thu -[basepage.py:56 - click_element() ] - INFO : Clicked on element using locator->('css selector', 'a[href$="Signup"]>span')
12-12-2024 05:02:06 AM Thu -[basepage.py:204 - switch_contexts() ] - INFO : Available Context(s)-> ['NATIVE_APP']
12-12-2024 05:02:06 AM Thu -[basepage.py:205 - switch_contexts() ] - INFO : Switched to Context-> NATIVE_APP
Also on my actual Android phone and even emulator it works like a charm but getting issues only on Device Farm.
Please help me on this issue as I am struggling to use the AWS device farm for Android app