@@ -26,12 +26,45 @@ def PATH(p): return os.path.abspath(
26
26
27
27
def get_desired_capabilities (app ):
28
28
desired_caps = {
29
- 'deviceName' : 'iPhone 6s' ,
29
+ 'deviceName' : iphone_device_name () ,
30
30
'platformName' : 'iOS' ,
31
31
'platformVersion' : '10.3' ,
32
32
'app' : PATH ('../../apps/' + app ),
33
33
'automationName' : 'XCUITest' ,
34
- 'allowTouchIdEnroll' : True
34
+ 'allowTouchIdEnroll' : True ,
35
+ 'wdaLocalPort' : wda_port (),
35
36
}
36
37
37
38
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