Skip to content

Commit 87fe7d2

Browse files
authored
Add xdist port handling (#248)
* add handling port number to run ios tests in parallel * define PytestXdistWorker * use gw0 if the number of worker is over the count of workers
1 parent 3224f5a commit 87fe7d2

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,23 @@ download and unarchive the source tarball (Appium-Python-Client-X.X.tar.gz).
4646
$ python -m autopep8 -r --global-config .config-pep8 -i .
4747
```
4848
49+
## Run tests
50+
51+
```
52+
$ py.test test/functional/ios/find_by_ios_class_chain_tests.py
53+
```
54+
55+
### In parallel for iOS
56+
1. Create simulators named 'iPhone 6s - 8100' and 'iPhone 6s - 8101'
57+
2. Install test libraries via pip
58+
```
59+
$ pip install pytest pytest-xdist
60+
```
61+
3. Run tests
62+
```
63+
$ py.test -n 2 test/functional/ios/find_by_ios_class_chain_tests.py
64+
```
65+
4966
# Usage
5067
5168
The Appium Python Client is fully compliant with the Selenium 3.0 specification

test/functional/ios/desired_capabilities.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,45 @@ def PATH(p): return os.path.abspath(
2626

2727
def get_desired_capabilities(app):
2828
desired_caps = {
29-
'deviceName': 'iPhone 6s',
29+
'deviceName': iphone_device_name(),
3030
'platformName': 'iOS',
3131
'platformVersion': '10.3',
3232
'app': PATH('../../apps/' + app),
3333
'automationName': 'XCUITest',
34-
'allowTouchIdEnroll': True
34+
'allowTouchIdEnroll': True,
35+
'wdaLocalPort': wda_port(),
3536
}
3637

3738
return desired_caps
39+
40+
41+
class PytestXdistWorker(object):
42+
NUMBER = os.getenv('PYTEST_XDIST_WORKER')
43+
COUNT = os.getenv('PYTEST_XDIST_WORKER_COUNT') # Return 2 if `-n 2` is passed
44+
45+
@staticmethod
46+
def gw(number):
47+
if number >= PytestXdistWorker.COUNT:
48+
return 'gw0'
49+
50+
return 'gw{}'.format(number)
51+
52+
# If you run tests with pytest-xdist, you can run tests in parallel.
53+
54+
55+
def wda_port():
56+
if PytestXdistWorker.NUMBER == PytestXdistWorker.gw(1):
57+
return 8101
58+
59+
return 8100
60+
61+
# Before running tests, you must have iOS simulators named 'iPhone 6s - 8100' and 'iPhone 6s - 8101'
62+
63+
64+
def iphone_device_name():
65+
if PytestXdistWorker.NUMBER == PytestXdistWorker.gw(0):
66+
return 'iPhone 6s - 8100'
67+
elif PytestXdistWorker.NUMBER == PytestXdistWorker.gw(1):
68+
return 'iPhone 6s - 8101'
69+
70+
return 'iPhone 6s'

0 commit comments

Comments
 (0)