|
1 | 1 | Appium Python Client |
2 | 2 | ==================== |
3 | 3 |
|
4 | | -An extension library for adding [Selenium 3.0 draft](https://code.google.com/p/selenium/source/browse/spec-draft.md?repo=mobile) functionality to [Appium](https://github.com/appium/appium). |
| 4 | +An extension library for adding [Selenium 3.0 draft](https://dvcs.w3.org/hg/webdriver/raw-file/tip/webdriver-spec.html) and [Mobile JSON Wire Protocol Specification draft](https://code.google.com/p/selenium/source/browse/spec-draft.md?repo=mobile) |
| 5 | +functionality to the Python language bindings, for use with the mobile testing |
| 6 | +framework [Appium](https://appium.io). |
5 | 7 |
|
| 8 | +# Usage |
6 | 9 |
|
| 10 | +The Appium Python Client is fully compliant with the Selenium 3.0 specification |
| 11 | +draft, with some helpers to make mobile testing in Python easier. The majority of |
| 12 | +the usage remains as it has been for Selenium 2 (WebDriver), and as the [official |
| 13 | +Selenium Python bindings](https://pypi.python.org/pypi/selenium) begins to |
| 14 | +implement the new specification that implementation will be used underneath, so |
| 15 | +test code can be written that is utilizable with both bindings. |
| 16 | + |
| 17 | +To use the new functionality now, and to use the superset of functions, instead of |
| 18 | +including the Selenium `webdriver` module in your test code, use that from |
| 19 | +Appium instead. |
| 20 | + |
| 21 | +```python |
| 22 | +from appium import webdriver |
| 23 | +``` |
| 24 | + |
| 25 | +From there much of your test code will work with no change. |
| 26 | + |
| 27 | +As a base for the following code examples, the following sets up the [UnitTest](https://docs.python.org/2/library/unittest.html) |
| 28 | +environment: |
| 29 | + |
| 30 | +```python |
| 31 | +from appium import webdriver |
| 32 | + |
| 33 | +desired_caps = {} |
| 34 | +desired_caps['device'] = 'Android' |
| 35 | +desired_caps['browserName'] = '' |
| 36 | +desired_caps['version'] = '4.2' |
| 37 | +desired_caps['app'] = PATH('../../../apps/selendroid-test-app.apk') |
| 38 | +desired_caps['app-package'] = 'io.selendroid.testapp' |
| 39 | +desired_caps['app-activity'] = '.HomeScreenActivity' |
| 40 | + |
| 41 | +self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) |
| 42 | +``` |
| 43 | + |
| 44 | +## Changed or added functionality |
| 45 | + |
| 46 | +The methods that do change are... |
| 47 | + |
| 48 | + |
| 49 | +### Switching between 'Native' and 'Webview' |
| 50 | + |
| 51 | +For mobile testing the Selnium methods for switching between windows was previously |
| 52 | +commandeered for switching between native applications and webview contexts. Methods |
| 53 | +explicitly for this have been added to the Selenium 3 specification, so moving |
| 54 | +forward these 'context' methods are to be used. |
| 55 | + |
| 56 | +To get the current context, rather than calling `driver.current_window_handle` you |
| 57 | +use |
| 58 | + |
| 59 | +```python |
| 60 | +current = driver.context |
| 61 | +``` |
| 62 | + |
| 63 | +The available contexts are not retrieved using `driver.window_handles` but with |
| 64 | + |
| 65 | +```python |
| 66 | +driver.contexts |
| 67 | +``` |
| 68 | + |
| 69 | +Finally, to switch to a new context, rather than `driver.switch_to.window(name)`, |
| 70 | +use the comparable context method |
| 71 | + |
| 72 | +```python |
| 73 | +context_name = "WEBVIEW_1" |
| 74 | +driver.switch_to.context(context_name) |
| 75 | +``` |
0 commit comments