Skip to content

Commit e2b0c9e

Browse files
committed
Add PyPi packaging setup
1 parent 3700ce9 commit e2b0c9e

File tree

5 files changed

+250
-13
lines changed

5 files changed

+250
-13
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@
88

99
*.pyc
1010

11+
MANIFEST
12+
1113
build
14+
dist

MANIFEST.in

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include LICENSE
2+
recursive-include docs *

README.md

+208
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,211 @@ Zoom in on an element, doing a pinch out operation.
230230
#### `driver.pinch`
231231

232232
Zoom out on an element, doing a pinch in operation.
233+
234+
235+
236+
### Application management methods
237+
238+
There are times when you want, in your tests, to manage the running application,
239+
such as installing or removing an application, etc.
240+
241+
242+
#### Backgrounding an application
243+
244+
The method `driver.background_app` sends the running application to the background
245+
for the specified amount of time, in seconds. After that time, the application is
246+
brought back to the foreground.
247+
248+
```python
249+
driver.background_app(1)
250+
sleep(2)
251+
el = driver.find_element_by_name('Animation')
252+
assertIsNotNone(el)
253+
```
254+
255+
256+
#### Checking if an application is installed
257+
258+
To check if an application is currently installed on the device, use the `device.is_app_installed`
259+
method. This method takes the bundle id of the application and return `True` or
260+
`False`.
261+
262+
```python
263+
assertFalse(self.driver.is_app_installed('sdfsdf'))
264+
assertTrue(self.driver.is_app_installed('com.example.android.apis'))
265+
```
266+
267+
268+
#### Installing an application
269+
270+
To install an uninstalled application on the device, use `device.install_app`,
271+
sending in the path to the application file or archive.
272+
273+
```python
274+
assertFalse(driver.is_app_installed('io.selendroid.testapp'))
275+
driver.install_app('/Users/isaac/code/python-client/test/apps/selendroid-test-app.apk')
276+
assertTrue(driver.is_app_installed('io.selendroid.testapp'))
277+
```
278+
279+
280+
#### Removing an application
281+
282+
If you need to remove an application from the device, use `device.remove_app`,
283+
passing in the application id.
284+
285+
```python
286+
assertTrue(driver.is_app_installed('com.example.android.apis'))
287+
driver.remove_app('com.example.android.apis')
288+
assertFalse(driver.is_app_installed('com.example.android.apis'))
289+
```
290+
291+
292+
#### Closing and Launching an application
293+
294+
To launch the application specified in the desired capabilities, call `driver.launch_app`.
295+
Closing that application is initiated by `driver.close_app`
296+
297+
```python
298+
el = driver.find_element_by_name('Animation')
299+
assertIsNotNone(el)
300+
driver.close_app();
301+
302+
try:
303+
driver.find_element_by_name('Animation')
304+
except Exception as e:
305+
pass # should not exist
306+
307+
driver.launch_app()
308+
el = driver.find_element_by_name('Animation')
309+
assertIsNotNone(el)
310+
```
311+
312+
313+
### Other methods
314+
315+
316+
#### Retrieving application strings
317+
318+
The property method `driver.app_strings` returns the application strings from
319+
the application on the device.
320+
321+
```python
322+
strings = driver.app_strings
323+
```
324+
325+
326+
#### Sending a key event to an Android device
327+
328+
The `driver.keyevent` method sends a keycode to the device. The keycodes can be
329+
found [here](http://developer.android.com/reference/android/view/KeyEvent.html).
330+
Android only.
331+
332+
```python
333+
# sending 'Home' key event
334+
driver.keyevent(3)
335+
```
336+
337+
338+
#### Retrieving the current running activity
339+
340+
The property method `driver.current_activity` returns the name of the current
341+
activity running on the device.
342+
343+
```python
344+
activity = driver.current_activity
345+
assertEquals('.ApiDemos', activity)
346+
```
347+
348+
349+
#### Set a value directly on an element
350+
351+
Sometimes one needs to directly set the value of an element on the device. To do
352+
this, the method `driver.set_value` or `element.set_value` is invoked.
353+
354+
```python
355+
el = driver.find_element_by_class_name('android.widget.EditText')
356+
driver.set_value(el, 'Testing')
357+
358+
text = el.get_attribute('text')
359+
assertEqual('Testing', text)
360+
361+
el.set_value('More testing')
362+
text = el.get_attribute('text')
363+
assertEqual('More testing', text)
364+
```
365+
366+
367+
#### Retrieve a file from the device
368+
369+
To retrieve the contents of a file from the device, use `driver.pull_file`, which
370+
returns the contents of the specified file encoded in [Base64](https://docs.python.org/2/library/base64.html).
371+
372+
```python
373+
# pulling the strings file for our application
374+
data = driver.pull_file('data/local/tmp/strings.json')
375+
strings = json.loads(data.decode('base64', 'strict'))
376+
assertEqual('You can\'t wipe my data, you are a monkey!', strings[u'monkey_wipe_data'])
377+
```
378+
379+
380+
#### Place a file on the device
381+
382+
To put a file onto the device at a particular place, use the `driver.push_file`
383+
method, which takes the path and the data, encoded as [Base64](https://docs.python.org/2/library/base64.html), to be written to the file.
384+
385+
```python
386+
path = 'data/local/tmp/test_push_file.txt'
387+
data = 'This is the contents of the file to push to the device.'
388+
driver.push_file(path, data.encode('base64'))
389+
data_ret = driver.pull_file('data/local/tmp/test_push_file.txt').decode('base64')
390+
self.assertEqual(data, data_ret)
391+
```
392+
393+
394+
#### Complex find in Android
395+
396+
Appium supports a way to do complex searches for elements on an Android device.
397+
This is accessed through `driver.complex_find`. The arguments and use case,
398+
to borrow from Winston Churchill, remain a riddle, wrapped in a mystery, inside
399+
an enigma.
400+
401+
```python
402+
el = self.driver.complex_find([[[2, 'Ani']]])
403+
self.assertIsNotNone(el)
404+
```
405+
406+
407+
def end_test_coverage(self, intent, path):
408+
"""Ends the coverage collection and pull the coverage.ec file from the device.
409+
Android only.
410+
411+
See https://github.com/appium/appium/blob/master/docs/en/android_coverage.md
412+
413+
:Args:
414+
- intent - description of operation to be performed
415+
- path - path to coverage.ec file to be pulled from the device
416+
"""
417+
data = {
418+
'intent': intent,
419+
'path': path
420+
}
421+
self.execute(Command.END_TEST_COVERAGE, data)
422+
return self
423+
424+
def lock(self, seconds):
425+
"""Lock the device for a certain period of time. iOS only.
426+
427+
:Args:
428+
- the duration to lock the device, in seconds
429+
"""
430+
data = {
431+
'seconds': seconds
432+
}
433+
self.execute(Command.LOCK, data)
434+
return self
435+
436+
def shake(self):
437+
"""Shake the device.
438+
"""
439+
self.execute(Command.SHAKE)
440+
return self

appium/webdriver/webdriver.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def complex_find(self, selector):
351351

352352
def background_app(self, seconds):
353353
"""Puts the application in the background on the device for a certain
354-
duration. iOS only.
354+
duration.
355355
356356
:Args:
357357
- seconds - the duration for the application to remain in the background

setup.py

+36-12
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,39 @@
1414

1515
from distutils.core import setup
1616

17-
setup(name='Python-Client',
18-
version='0.1',
19-
description='Appium Python Client',
20-
author='Isaac Murchie',
21-
author_email='[email protected]',
22-
url='http://appium.io/',
23-
packages=['appium',
24-
'appium.common',
25-
'appium.webdriver',
26-
'appium.webdriver.common'],
27-
license='Apache 2.0'
28-
)
17+
setup(
18+
name='Appium-Python-Client',
19+
version='0.1',
20+
description='Python client for Appium 1.0',
21+
keywords=[
22+
'appium',
23+
'appium 1.0',
24+
'selenium',
25+
'selenium 3',
26+
'python client',
27+
'mobile automation'
28+
],
29+
author='Isaac Murchie',
30+
author_email='[email protected]',
31+
url='http://appium.io/',
32+
packages=[
33+
'appium',
34+
'appium.common',
35+
'appium.webdriver',
36+
'appium.webdriver.common'
37+
],
38+
license='Apache 2.0',
39+
classifiers=[
40+
'Development Status :: 3 - Alpha',
41+
'Programming Language :: Python',
42+
'Environment :: Console',
43+
'Environment :: MacOS X',
44+
'Environment :: Win32 (MS Windows)',
45+
'Intended Audience :: Developers',
46+
'Intended Audience :: Other Audience',
47+
'License :: OSI Approved :: Apache Software License',
48+
'Operating System :: OS Independent',
49+
'Topic :: Software Development :: Quality Assurance',
50+
'Topic :: Software Development :: Testing'
51+
]
52+
)

0 commit comments

Comments
 (0)