@@ -26,12 +26,45 @@ def PATH(p): return os.path.abspath(
2626
2727def 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