-
Notifications
You must be signed in to change notification settings - Fork 568
Expand file tree
/
Copy pathdesired_capabilities.py
More file actions
84 lines (58 loc) · 2.5 KB
/
Copy pathdesired_capabilities.py
File metadata and controls
84 lines (58 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
from typing import Any, Dict, Optional
# Returns abs path relative to this file and not cwd
def PATH(p: str) -> str:
return os.path.abspath(os.path.join(os.path.dirname(__file__), p))
BUNDLE_ID = 'com.example.apple-samplecode.UICatalog'
def get_desired_capabilities(app: Optional[str] = None) -> Dict[str, Any]:
desired_caps: Dict[str, Any] = {
'deviceName': iphone_device_name(),
'platformName': 'iOS',
'platformVersion': os.getenv('IOS_VERSION') or '17.4',
'automationName': 'XCUITest',
'allowTouchIdEnroll': True,
'wdaLocalPort': wda_port(),
'simpleIsVisibleCheck': True,
}
if app is not None:
desired_caps['app'] = PATH(os.path.join('../../..', 'apps', app))
local_prebuilt_wda = os.getenv('LOCAL_PREBUILT_WDA')
if local_prebuilt_wda:
desired_caps['usePreinstalledWDA'] = True
desired_caps['prebuiltWDAPath'] = local_prebuilt_wda
return desired_caps
class PytestXdistWorker:
NUMBER: Optional[str] = os.getenv('PYTEST_XDIST_WORKER')
COUNT: Optional[str] = os.getenv('PYTEST_XDIST_WORKER_COUNT') # Return 2 if `-n 2` is passed
@staticmethod
def gw(number: int) -> str:
if PytestXdistWorker.COUNT is None:
return '0'
if number >= int(PytestXdistWorker.COUNT):
return 'gw0'
return f'gw{number}'
# If you run tests with pytest-xdist, you can run tests in parallel.
def wda_port() -> int:
if PytestXdistWorker.NUMBER == PytestXdistWorker.gw(1):
return 8101
return 8100
# Before running tests, you must have iOS simulators named 'iPhone 12 - 8100' and 'iPhone 12 - 8101'
def iphone_device_name() -> str:
prefix = os.getenv('IPHONE_MODEL') or 'iPhone 15 Plus'
if PytestXdistWorker.NUMBER == PytestXdistWorker.gw(0):
return f'{prefix} - 8100'
elif PytestXdistWorker.NUMBER == PytestXdistWorker.gw(1):
return f'{prefix} - 8101'
return prefix