Skip to content

Python language bindings for Appium

License

lundstrj/python-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Appium Python Client

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.

Usage

The 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 webdriver

From 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['device'] = 'Android' desired_caps['browserName'] = '' desired_caps['version'] = '4.2' desired_caps['app'] = PATH('../../../apps/selendroid-test-app.apk') desired_caps['app-package'] = 'io.selendroid.testapp' desired_caps['app-activity'] = '.HomeScreenActivity' self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
# iOS environment import unittest from appium import webdriver desired_caps = {} desired_caps['app'] = PATH('../../apps/UICatalog.app.zip') self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

Changed or added functionality

The methods that do change are...

Switching between 'Native' and 'Webview'

For mobile testing the Selnium 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.context

The available contexts are not retrieved using driver.window_handles but with

driver.contexts

Finally, 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)

Finding elements by iOS UIAutomation search

This allows elements in iOS applications to be found using recursive element search using the UIAutomation library. 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)

Finding elements by Android UIAutomator search

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)

Finding elements by Accessibility ID

Allows for elements to be found using the "Accessibility ID". The methods take a string representing the accessibility id or label attached to a given element, e.g., for iOS the accessibility identifier and for Android the content-description. Adds the methods driver.find_element_by_accessibility_id and find_elements_by_accessibility_id.

el = self.driver.find_element_by_accessibility_id('Animation') self.assertIsNotNone(el)
els = self.driver.find_elements_by_accessibility_id('Animation') self.assertIsInstance(els, list)

About

Python language bindings for Appium

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%