An extension library for adding Selenium 3.0 draft and Mobile JSON Wire Protocol Specification draft functionality to the Python language bindings, for use with the mobile testing framework Appium.
Since v1.0.0 only Python 3 is supported
There are three ways to install and use the Appium Python client.
-
Install from PyPi, as 'Appium-Python-Client'.
pip install Appium-Python-Client
You can see the history from here
-
Install from source, via PyPi. From 'Appium-Python-Client', download and unarchive the source tarball (Appium-Python-Client-X.X.tar.gz).
tar -xvf Appium-Python-Client-X.X.tar.gz cd Appium-Python-Client-X.X python setup.py install -
Install from source via GitHub.
git clone git@github.com:appium/python-client.git cd python-client python setup.py install
- Style Guide: https://www.python.org/dev/peps/pep-0008/
autopep8helps to format code automatically$ python -m autopep8 -r --global-config .config-pep8 -i .isorthelps to order imports automatically$ python -m isort -rc .- When you use newly 3rd party modules, add it to .isort.cfg to keep import order correct
- Docstring style: Google Style
- Refer link
- You can customise
CHANGELOG.rstwith commit messages following .gitchangelog.rc- It generates readable changelog
- Setup
pip install --user pipenvpython -m pipenv lock --clear- If you experience the below error, then refer pypa/pipenv#187 to solve it.
Locking Failed! unknown locale: UTF-8
- If you experience the below error, then refer pypa/pipenv#187 to solve it.
python -m pipenv install --dev --systempre-commit install
You can run all of tests running on CI via tox in your local.
$ tox
You also can run particular tests like below.
$ pytest test/unit
Run with pytest-xdist
$ pytest -n 2 test/unit
$ pytest test/functional/ios/search_context/find_by_ios_class_chain_tests.py
- Create simulators named 'iPhone 8 - 8100' and 'iPhone 8 - 8101'
- Install test libraries via pip
$ pip install pytest pytest-xdist - Run tests
$ pytest -n 2 test/functional/ios/search_context/find_by_ios_class_chain_tests.py
Follow below steps.
$ pip install twine
$ pip install git+git://github.com/vaab/gitchangelog.git # Getting via GitHub repository is necessary for Python 3.7
# Type the new version number and 'yes' if you can publish it
# You can test the command with DRY_RUN
$ DRY_RUN=1 ./release.sh
$ ./release.sh # releaseThe Appium Python Client is fully compliant with the Selenium 3.0 specification draft, with some helpers to make mobile testing in Python easier. The majority of the usage remains as it has been for Selenium 2 (WebDriver), and as the official Selenium Python bindings begins to implement the new specification that implementation will be used underneath, so test code can be written that is utilizable with both bindings.
To use the new functionality now, and to use the superset of functions, instead of
including the Selenium webdriver module in your test code, use that from
Appium instead.
from appium import webdriverFrom there much of your test code will work with no change.
As a base for the following code examples, the following sets up the UnitTest environment:
# Android environment
import unittest
from appium import webdriver
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '8.1'
desired_caps['automationName'] = 'uiautomator2'
desired_caps['deviceName'] = 'Android Emulator'
desired_caps['app'] = PATH('../../../apps/selendroid-test-app.apk')
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)# iOS environment
import unittest
from appium import webdriver
desired_caps = {}
desired_caps['platformName'] = 'iOS'
desired_caps['platformVersion'] = '11.4'
desired_caps['automationName'] = 'xcuitest'
desired_caps['deviceName'] = 'iPhone Simulator'
desired_caps['app'] = PATH('../../apps/UICatalog.app.zip')
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)The methods that do change are...
If your Selenium/Appium server decorates the new session capabilities response with the following keys:
directConnectProtocoldirectConnectHostdirectConnectPortdirectConnectPath
Then python client will switch its endpoint to the one specified by the values of those keys.
import unittest
from appium import webdriver
desired_caps = {}
desired_caps['platformName'] = 'iOS'
desired_caps['platformVersion'] = '11.4'
desired_caps['automationName'] = 'xcuitest'
desired_caps['deviceName'] = 'iPhone Simulator'
desired_caps['app'] = PATH('../../apps/UICatalog.app.zip')
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps, direct_connection=True)For mobile testing the Selenium methods for switching between windows was previously commandeered for switching between native applications and webview contexts. Methods explicitly for this have been added to the Selenium 3 specification, so moving forward these 'context' methods are to be used.
To get the current context, rather than calling driver.current_window_handle you
use
current = driver.current_contextThe available contexts are not retrieved using driver.window_handles but with
driver.contextsFinally, to switch to a new context, rather than driver.switch_to.window(name),
use the comparable context method
context_name = "WEBVIEW_1"
driver.switch_to.context(context_name)This allows elements in iOS applications to be found using recursive element search using the UIAutomation library. This method is supported on iOS devices that still support UIAutomation, that is, versions which predate XCUITEST.
Adds the methods driver.find_element_by_ios_uiautomation
and driver.find_elements_by_ios_uiautomation.
el = self.driver.find_element_by_ios_uiautomation('.elements()[0]')
self.assertEqual('UICatalog', el.get_attribute('name'))els = self.driver.find_elements_by_ios_uiautomation('.elements()')
self.assertIsInstance(els, list)This allows elements in an Android application to be found using recursive element
search using the UIAutomator library. Adds the methods driver.find_element_by_android_uiautomator
and driver.find_elements_by_android_uiautomator.
el = self.driver.find_element_by_android_uiautomator('new UiSelector().description("Animation")')
self.assertIsNotNone(el)els = self.driver.find_elements_by_android_uiautomator('new UiSelector().clickable(true)') self.assertIsInstance(els, list)