Skip to content

Commit c5676e5

Browse files
authored
feat: enable not strict ios simulator versions (#422)
* feat: enable not strict ios simulator versions Enable not strict iOS simulator versions. Reason behind this: - Xcode 11 do not provide older version of iOS13 except latest - That cause variaty of iOS 13.0, 13.1, 13.2 and so on versions on different machines (it may be machine of external contributor as well) - We need to give a chance for everyone to run those tests instead of hardcoding fixed version. * chore: fix cases when watchTV sdk is available
1 parent 1d18d78 commit c5676e5

File tree

3 files changed

+41
-21
lines changed

3 files changed

+41
-21
lines changed

core/settings/Settings.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,10 @@ class Emulators(object):
193193

194194

195195
class Simulators(object):
196-
SIM_IOS10 = SimulatorInfo(name=os.environ.get('SIM_IOS10', 'iPhone7_10'), device_type='iPhone 7', sdk=10.0)
197-
SIM_IOS11 = SimulatorInfo(name=os.environ.get('SIM_IOS11', 'iPhone7_11'), device_type='iPhone 7', sdk=11.2)
198-
SIM_IOS12 = SimulatorInfo(name=os.environ.get('SIM_IOS12', 'iPhoneXR_12'), device_type='iPhone XR', sdk=12.0)
199-
SIM_IOS13 = SimulatorInfo(name=os.environ.get('SIM_IOS13', 'iPhoneXR_13'), device_type='iPhone XR', sdk=13.1)
196+
SIM_IOS10 = SimulatorInfo(name=os.environ.get('SIM_IOS10', 'iPhone7_10'), device_type='iPhone 7', sdk=10)
197+
SIM_IOS11 = SimulatorInfo(name=os.environ.get('SIM_IOS11', 'iPhone7_11'), device_type='iPhone 7', sdk=11)
198+
SIM_IOS12 = SimulatorInfo(name=os.environ.get('SIM_IOS12', 'iPhoneXR_12'), device_type='iPhone XR', sdk=12)
199+
SIM_IOS13 = SimulatorInfo(name=os.environ.get('SIM_IOS13', 'iPhoneXR_13'), device_type='iPhone XR', sdk=13)
200200
DEFAULT = SIM_IOS12
201201

202202

core/utils/device/device_manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ def ensure_available(emulator, force_start=False):
129129
class Simulator(object):
130130
@staticmethod
131131
def create(simulator_info):
132+
exact_sdk_verson = Simctl.get_max_runtime_version(simulator_info.sdk)
132133
cmd = 'xcrun simctl create {0} "{1}" com.apple.CoreSimulator.SimRuntime.iOS-{2}' \
133-
.format(simulator_info.name, simulator_info.device_type, str(simulator_info.sdk).replace('.', '-'))
134+
.format(simulator_info.name, simulator_info.device_type, exact_sdk_verson.replace('.', '-'))
134135
result = run(cmd=cmd, timeout=60)
135136
assert result.exit_code == 0, 'Failed to create iOS Simulator with name {0}'.format(simulator_info.name)
136137
assert '-' in result.output, 'Failed to create iOS Simulator with name {0}'.format(simulator_info.name)

core/utils/device/simctl.py

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,39 @@ def __get_simulators():
2626
Log.error('Failed to parse json ' + os.linesep + result.output)
2727
return json.loads('{}')
2828

29+
# noinspection PyBroadException
30+
@staticmethod
31+
def get_max_runtime_version(version):
32+
# Parse runtimes
33+
result = Simctl.run_simctl_command(command='list --json runtimes')
34+
runtimes = None
35+
try:
36+
runtimes = json.loads(result.output)
37+
except ValueError:
38+
Log.error('Failed to parse json ' + os.linesep + result.output)
39+
return json.loads('{}')
40+
41+
# Get max runtime version
42+
exact_sdk_version = None
43+
for runtime in runtimes['runtimes']:
44+
if str(version) in runtime['version'] and runtime['name'].startswith('iOS') and runtime['isAvailable']:
45+
exact_sdk_version = runtime['version']
46+
if exact_sdk_version is None:
47+
raise Exception('Can not find iOS SDK {0}'.format(version))
48+
49+
return exact_sdk_version
50+
51+
@staticmethod
52+
def __get_devices_by_version(version):
53+
exact_sdk_version = Simctl.get_max_runtime_version(version)
54+
devices = Simctl.__get_simulators()['devices']
55+
placeholder = 'iOS {0}'
56+
device_key = placeholder.format(exact_sdk_version)
57+
if device_key not in devices:
58+
placeholder_dash = placeholder.format(exact_sdk_version).replace(' ', '-').replace('.', '-')
59+
device_key = 'com.apple.CoreSimulator.SimRuntime.{0}'.format(placeholder_dash)
60+
return devices[device_key]
61+
2962
@staticmethod
3063
def __get_availability(sim):
3164
available = False
@@ -46,14 +79,7 @@ def start(simulator_info):
4679

4780
@staticmethod
4881
def is_running(simulator_info):
49-
devices = Simctl.__get_simulators()['devices']
50-
placeholder = 'iOS {0}'
51-
device_key = placeholder.format(simulator_info.sdk)
52-
if device_key not in devices:
53-
placeholder_dash = placeholder.format(simulator_info.sdk).replace(' ', '-').replace('.', '-')
54-
device_key = 'com.apple.CoreSimulator.SimRuntime.{0}'.format(placeholder_dash)
55-
sims = devices[device_key]
56-
for sim in sims:
82+
for sim in Simctl.__get_devices_by_version(simulator_info.sdk):
5783
if sim['name'] == simulator_info.name and sim['state'] == 'Booted':
5884
# simctl returns Booted too early, so we will wait some untill service is started
5985
simulator_info.id = str(sim['udid'])
@@ -85,14 +111,7 @@ def wait_until_boot(simulator_info, timeout=180):
85111

86112
@staticmethod
87113
def is_available(simulator_info):
88-
devices = Simctl.__get_simulators()['devices']
89-
placeholder = 'iOS {0}'
90-
device_key = placeholder.format(simulator_info.sdk)
91-
if device_key not in devices:
92-
placeholder_dash = placeholder.format(simulator_info.sdk).replace(' ', '-').replace('.', '-')
93-
device_key = 'com.apple.CoreSimulator.SimRuntime.{0}'.format(placeholder_dash)
94-
sims = devices[device_key]
95-
for sim in sims:
114+
for sim in Simctl.__get_devices_by_version(simulator_info.sdk):
96115
if sim['name'] == simulator_info.name and Simctl.__get_availability(sim):
97116
simulator_info.id = str(sim['udid'])
98117
return simulator_info

0 commit comments

Comments
 (0)