def _create_simulators(self): if (self.default_child_processes() < self.child_processes()): _log.warn( 'You have specified very high value({0}) for --child-processes' .format(self.child_processes())) _log.warn( 'maximum child-processes which can be supported on this system are: {0}' .format(self.default_child_processes())) _log.warn('This is very likely to fail.') if self._using_dedicated_simulators(): atexit.register(lambda: self._teardown_managed_simulators()) if self.use_multiple_simulator_apps(): self._createSimulatorApps() for i in xrange(self.child_processes()): self._create_device(i) for i in xrange(self.child_processes()): device_udid = Simulator.managed_devices[i].udid Simulator.wait_until_device_is_in_state( device_udid, Simulator.DeviceState.SHUTDOWN) Simulator.reset_device(device_udid) else: assert (self._current_device) if self._current_device.platform_device.name != self.simulator_device_type( ).name: _log.warn("Expected simulator of type '" + self.simulator_device_type().name + "' but found simulator of type '" + self._current_device.platform_device.name + "'") _log.warn( 'The next block of tests may fail due to device mis-match')
def _teardown_managed_simulators(self): if not self._using_dedicated_simulators(): return self._quit_ios_simulator() for i in xrange(len(Simulator.managed_devices)): simulator_path = self.get_simulator_path(i) device_udid = Simulator.managed_devices[i].udid Simulator.remove_device(i) if not os.path.exists(simulator_path): continue try: self._executive.run_command([IOSSimulatorPort.LSREGISTER_PATH, "-u", simulator_path]) _log.debug('rmtree %s', simulator_path) self._filesystem.rmtree(simulator_path) logs_path = self._filesystem.join(self._filesystem.expanduser("~"), "Library/Logs/CoreSimulator/", device_udid) _log.debug('rmtree %s', logs_path) self._filesystem.rmtree(logs_path) saved_state_path = self._filesystem.join(self._filesystem.expanduser("~"), "Library/Saved Application State/", IOSSimulatorPort.SIMULATOR_BUNDLE_ID + str(i) + ".savedState") _log.debug('rmtree %s', saved_state_path) self._filesystem.rmtree(saved_state_path) except: _log.warning('Unable to remove Simulator' + str(i))
def _create_devices(self, device_class): mac_os_version = self.host.platform.os_version self._set_device_class(device_class) _log.debug('') _log.debug('setup_test_run for %s', self._device_class) self._create_simulators() if not self._using_dedicated_simulators(): return for i in xrange(self.child_processes()): device_udid = Simulator.managed_devices[i].udid _log.debug('testing device %s has udid %s', i, device_udid) # FIXME: <rdar://problem/20916140> Switch to using CoreSimulator.framework for launching and quitting iOS Simulator self._executive.run_command([ 'open', '-g', '-b', self.SIMULATOR_BUNDLE_ID + str(i), '--args', '-CurrentDeviceUDID', device_udid]) if mac_os_version in ['elcapitan', 'yosemite', 'mavericks']: time.sleep(2.5) _log.info('Waiting for all iOS Simulators to finish booting.') for i in xrange(self.child_processes()): Simulator.wait_until_device_is_booted(Simulator.managed_devices[i].udid) IOSSimulatorPort._DEVICE_MAP = {} for i in xrange(self.child_processes()): IOSSimulatorPort._DEVICE_MAP[i] = Device(Simulator.managed_devices[i])
def check_sys_deps(self, needs_http): if not self.simulator_runtime.available: _log.error( 'The iOS Simulator runtime with identifier "{0}" cannot be used because it is unavailable.' .format(self.simulator_runtime.identifier)) return False testing_device = self.testing_device # May create a new simulator device # testing_device will fail to boot if it is already booted. We assume that if testing_device # is booted that it was booted by the iOS Simulator app (as opposed to simctl). So, quit the # iOS Simulator app to shutdown testing_device. self._executive.run_command([ 'osascript', '-e', 'tell application id "com.apple.iphonesimulator" to quit' ]) Simulator.wait_until_device_is_in_state(testing_device.udid, Simulator.DeviceState.SHUTDOWN) if not Simulator.check_simulator_device_and_erase_if_needed( self.host, testing_device.udid): _log.error( 'Unable to boot the simulator device with UDID {0}.'.format( testing_device.udid)) return False return super(IOSSimulatorPort, self).check_sys_deps(needs_http)
def setup_test_run(self, device_class=None): mac_os_version = self.host.platform.os_version self._set_device_class(device_class) _log.debug('') _log.debug('setup_test_run for %s', self._device_class) self._create_simulators() for i in xrange(self.child_processes()): device_udid = self._testing_device(i).udid _log.debug('testing device %s has udid %s', i, device_udid) # FIXME: <rdar://problem/20916140> Switch to using CoreSimulator.framework for launching and quitting iOS Simulator self._executive.run_command([ 'open', '-g', '-b', self.SIMULATOR_BUNDLE_ID + str(i), '--args', '-CurrentDeviceUDID', device_udid]) if mac_os_version in ['elcapitan', 'yosemite', 'mavericks']: time.sleep(2.5) _log.info('Waiting for all iOS Simulators to finish booting.') for i in xrange(self.child_processes()): Simulator.wait_until_device_is_booted(self._testing_device(i).udid)
def reset_preferences(self): # We assume that if testing_device is booted that it was booted by the iOS Simulator app # (as opposed to simctl). So, quit the iOS Simulator app to shutdown testing_device. self._quit_ios_simulator() Simulator.wait_until_device_is_in_state(self.testing_device.udid, Simulator.DeviceState.SHUTDOWN) data_path = os.path.join(self.testing_device.path, 'data') if os.path.isdir(data_path): shutil.rmtree(data_path)
def setup_test_run(self): device_udid = self.testing_device.udid self._executive.run_command([ 'open', '-a', os.path.join(self.developer_dir, 'Applications', 'iOS Simulator.app'), '--args', '-CurrentDeviceUDID', device_udid]) Simulator.wait_until_device_is_in_state(device_udid, Simulator.DeviceState.BOOTED) # FIXME: Pause here until SpringBoard finishes launching to workaround <rdar://problem/20000383>. boot_delay = 30 _log.debug('Waiting {seconds} seconds for iOS Simulator to finish booting ...'.format(seconds=boot_delay)) time.sleep(boot_delay)
def setup_test_run(self): device_udid = self.testing_device.udid # FIXME: <rdar://problem/20916140> Switch to using CoreSimulator.framework for launching and quitting iOS Simulator self._executive.run_command([ 'open', '-b', self.SIMULATOR_BUNDLE_ID, '--args', '-CurrentDeviceUDID', device_udid]) Simulator.wait_until_device_is_in_state(device_udid, Simulator.DeviceState.BOOTED) # FIXME: Pause here until SpringBoard finishes launching to workaround <rdar://problem/20000383>. boot_delay = 30 _log.debug('Waiting {seconds} seconds for iOS Simulator to finish booting ...'.format(seconds=boot_delay)) time.sleep(boot_delay)
def setup_test_run(self): device_udid = self.testing_device.udid # FIXME: <rdar://problem/20916140> Switch to using CoreSimulator.framework for launching and quitting iOS Simulator self._executive.run_command([ 'open', '-b', 'com.apple.iphonesimulator', '--args', '-CurrentDeviceUDID', device_udid]) Simulator.wait_until_device_is_in_state(device_udid, Simulator.DeviceState.BOOTED) # FIXME: Pause here until SpringBoard finishes launching to workaround <rdar://problem/20000383>. boot_delay = 30 _log.debug('Waiting {seconds} seconds for iOS Simulator to finish booting ...'.format(seconds=boot_delay)) time.sleep(boot_delay)
def shutdown(cls, udid): """ Shut down the given CoreSimulator device. :param udid: The udid of the device. :type udid: str """ device_state = Simulator.device_state(udid) if device_state == Simulator.DeviceState.BOOTING or device_state == Simulator.DeviceState.BOOTED: _log.debug('xcrun simctl shutdown %s', udid) # Don't throw on error. Device shutdown seems to be racy with Simulator app killing. subprocess.call(['xcrun', 'simctl', 'shutdown', udid]) Simulator.wait_until_device_is_in_state(udid, Simulator.DeviceState.SHUTDOWN)
def setup_test_run(self): mac_os_version = self.host.platform.os_version for i in xrange(self.child_processes()): device_udid = self.testing_device(i).udid # FIXME: <rdar://problem/20916140> Switch to using CoreSimulator.framework for launching and quitting iOS Simulator self._executive.run_command( ["open", "-b", self.SIMULATOR_BUNDLE_ID + str(i), "--args", "-CurrentDeviceUDID", device_udid] ) if mac_os_version in ["elcapitan", "yosemite", "mavericks"]: time.sleep(1) _log.info("Waiting for all iOS Simulators to finish booting.") for i in xrange(self.child_processes()): Simulator.wait_until_device_is_booted(self.testing_device(i).udid)
def setup_test_run(self): mac_os_version = self.host.platform.os_version for i in xrange(self.child_processes()): device_udid = self.testing_device(i).udid # FIXME: <rdar://problem/20916140> Switch to using CoreSimulator.framework for launching and quitting iOS Simulator self._executive.run_command([ 'open', '-b', self.SIMULATOR_BUNDLE_ID + str(i), '--args', '-CurrentDeviceUDID', device_udid]) if mac_os_version in ['elcapitan', 'yosemite', 'mavericks']: time.sleep(2.5) _log.info('Waiting for all iOS Simulators to finish booting.') for i in xrange(self.child_processes()): Simulator.wait_until_device_is_booted(self.testing_device(i).udid)
def _create_simulators(self): if (self.default_child_processes() < self.child_processes()): _log.warn("You have specified very high value({0}) for --child-processes".format(self.child_processes())) _log.warn("maximum child-processes which can be supported on this system are: {0}".format(self.default_child_processes())) _log.warn("This is very likely to fail.") self._createSimulatorApps() for i in xrange(self.child_processes()): self._create_device(i) for i in xrange(self.child_processes()): device_udid = self._testing_device(i).udid Simulator.wait_until_device_is_in_state(device_udid, Simulator.DeviceState.SHUTDOWN) Simulator.reset_device(device_udid)
def reset_preferences(self): if (self.default_child_processes() < self.child_processes()): _log.warn("You have specified very high value({0}) for --child-processes".format(self.child_processes())) _log.warn("maximum child-processes which can be supported on this system are: {0}".format(self.default_child_processes())) _log.warn("This is very likely to fail.") self._quit_ios_simulator() self._createSimulatorApps() for i in xrange(self.child_processes()): Simulator.wait_until_device_is_in_state(self.testing_device(i).udid, Simulator.DeviceState.SHUTDOWN) data_path = os.path.join(self.testing_device(i).path, 'data') if os.path.isdir(data_path): shutil.rmtree(data_path)
def check_sys_deps(self, needs_http): if not self.simulator_runtime.available: _log.error('The iOS Simulator runtime with identifier "{0}" cannot be used because it is unavailable.'.format(self.simulator_runtime.identifier)) return False testing_device = self.testing_device # May create a new simulator device # testing_device will fail to boot if it is already booted. We assume that if testing_device # is booted that it was booted by the iOS Simulator app (as opposed to simctl). So, quit the # iOS Simulator app to shutdown testing_device. self._executive.run_command(['osascript', '-e', 'tell application id "com.apple.iphonesimulator" to quit']) Simulator.wait_until_device_is_in_state(testing_device.udid, Simulator.DeviceState.SHUTDOWN) if not Simulator.check_simulator_device_and_erase_if_needed(self.host, testing_device.udid): _log.error('Unable to boot the simulator device with UDID {0}.'.format(testing_device.udid)) return False return super(IOSSimulatorPort, self).check_sys_deps(needs_http)
def test_invalid_device_types_header(self): """ Tests that an invalid Device Types header throws an exception """ self._set_expected_xcrun_simctl_list('''XX Device Types XX ''') with self.assertRaises(RuntimeError) as cm: Simulator(host=self._host) self.assertEqual('Expected == Device Types == header but got: "XX Device Types XX"', cm.exception.message)
def test_device_pairs(self): """ Tests that Device Pairs header does not cause parsing exception """ self._set_expected_xcrun_simctl_list('''== Device Types == iPhone 4s (com.apple.CoreSimulator.SimDeviceType.iPhone-4s) == Runtimes == iOS 8.0 (8.0 - 12A465) (com.apple.CoreSimulator.SimRuntime.iOS-8-0) iOS 8.0 Internal (8.0 - Unknown) (com.apple.CoreSimulator.SimRuntime.iOS-8-0-Internal) (unavailable, runtime path not found) == Devices == -- iOS 8.0 -- iPhone 4s (271BBEAC-1826-4CE1-B3AF-83F35CDD1D82) (Shutdown) == Device Pairs == ''') simulator = Simulator(host=self._host) self.assertEqual(1, len(simulator.device_types)) device_type_iphone_4s = simulator.device_types[0] self.assertEqual('iPhone 4s', device_type_iphone_4s.name) self.assertEqual('com.apple.CoreSimulator.SimDeviceType.iPhone-4s', device_type_iphone_4s.identifier) self.assertEqual(2, len(simulator.runtimes)) runtime_ios_8 = simulator.runtimes[0] self.assertEqual('com.apple.CoreSimulator.SimRuntime.iOS-8-0', runtime_ios_8.identifier) self.assertEqual(True, runtime_ios_8.available) self.assertEqual(False, runtime_ios_8.is_internal_runtime) self.assertEqual(tuple([8, 0]), runtime_ios_8.version) self.assertEqual(1, len(runtime_ios_8.devices)) device_iphone_4s = runtime_ios_8.devices[0] self.assertEqual('iPhone 4s', device_iphone_4s.name) self.assertEqual('271BBEAC-1826-4CE1-B3AF-83F35CDD1D82', device_iphone_4s.udid) self.assertEqual(True, device_iphone_4s.available) self.assertEqual(runtime_ios_8, device_iphone_4s.runtime)
def clean_up_test_run(self): super(IOSSimulatorPort, self).clean_up_test_run() self._quit_ios_simulator() fifos = [ path for path in os.listdir('/tmp') if re.search( 'org.webkit.(DumpRenderTree|WebKitTestRunner).*_(IN|OUT|ERROR)', path) ] for fifo in fifos: try: os.remove(os.path.join('/tmp', fifo)) except OSError: _log.warning('Unable to remove ' + fifo) pass for i in xrange(self.child_processes()): try: subprocess.call([ self.LSREGISTER_PATH, "-v", "-u", self.get_simulator_path(i) ]) shutil.rmtree(self.get_simulator_path(i), ignore_errors=True) shutil.rmtree(os.path.join(os.path.expanduser("~"), "Library/Logs/CoreSimulator/", self.testing_device(i).udid), ignore_errors=True) Simulator().delete_device(self.testing_device(i).udid) except: _log.warning('Unable to remove Simulator' + str(i))
def setup_test_run(self): device_udid = self.testing_device.udid self._executive.run_command([ 'open', '-a', os.path.join(self.developer_dir, 'Applications', 'iOS Simulator.app'), '--args', '-CurrentDeviceUDID', device_udid ]) Simulator.wait_until_device_is_in_state(device_udid, Simulator.DeviceState.BOOTED) # FIXME: Pause here until SpringBoard finishes launching to workaround <rdar://problem/20000383>. boot_delay = 30 _log.debug( 'Waiting {seconds} seconds for iOS Simulator to finish booting ...' .format(seconds=boot_delay)) time.sleep(boot_delay)
def test_invalid_runtimes_header(self): """ Tests that an invalid Runtimes header throws an exception """ self._set_expected_xcrun_simctl_list('''== Device Types == iPhone 4s (com.apple.CoreSimulator.SimDeviceType.iPhone-4s) XX Runtimes XX ''') with self.assertRaises(RuntimeError) as cm: Simulator(host=self._host) self.assertEqual('Expected == Runtimes == header but got: "XX Runtimes XX"', cm.exception.message)
def check_sys_deps(self, needs_http): if not self.simulator_runtime.available: _log.error('The iOS Simulator runtime with identifier "{0}" cannot be used because it is unavailable.'.format(self.simulator_runtime.identifier)) return False testing_device = self.testing_device # May create a new simulator device if not Simulator.check_simulator_device_and_erase_if_needed(self.host, testing_device.udid): _log.error('Unable to boot the simulator device with UDID {0}.'.format(testing_device.udid)) return False return super(IOSSimulatorPort, self).check_sys_deps(needs_http)
def _create_simulators(self): if (self.default_child_processes() < self.child_processes()): _log.warn("You have specified very high value({0}) for --child-processes".format(self.child_processes())) _log.warn("maximum child-processes which can be supported on this system are: {0}".format(self.default_child_processes())) _log.warn("This is very likely to fail.") if self._using_dedicated_simulators(): self._createSimulatorApps() for i in xrange(self.child_processes()): self._create_device(i) for i in xrange(self.child_processes()): device_udid = self._testing_device(i).udid Simulator.wait_until_device_is_in_state(device_udid, Simulator.DeviceState.SHUTDOWN) Simulator.reset_device(device_udid) else: assert(self._current_device) if self._current_device.name != self.simulator_device_type().name: _log.warn("Expected simulator of type '" + self.simulator_device_type().name + "' but found simulator of type '" + self._current_device.name + "'") _log.warn('The next block of tests may fail due to device mis-match')
def create(cls, name, device_type, runtime): """ Create a new CoreSimulator device. :param name: The name of the device. :type name: str :param device_type: The CoreSimulatort device type. :type device_type: DeviceType :param runtime: The CoreSimualtor runtime. :type runtime: Runtime :return: The new device or raises a CalledProcessError if ``simctl create`` failed. :rtype: Device """ device_udid = subprocess.check_output([ 'xcrun', 'simctl', 'create', name, device_type.identifier, runtime.identifier ]).rstrip() _log.debug('"xcrun simctl create %s %s %s" returned %s', name, device_type.identifier, runtime.identifier, device_udid) Simulator.wait_until_device_is_in_state(device_udid, Simulator.DeviceState.SHUTDOWN) return Simulator().find_device_by_udid(device_udid)
def reset(cls, udid): """ Reset the given CoreSimulator device. :param udid: The udid of the device. :type udid: str """ SimulatedDevice.shutdown(udid) try: _log.debug('xcrun simctl erase %s', udid) subprocess.check_call(['xcrun', 'simctl', 'erase', udid]) except subprocess.CalledProcessError: raise RuntimeError( '"xcrun simctl erase" failed: device state is {}'.format( Simulator.device_state(udid)))
def test_unavailable_devices(self): """ Tests that unavailable devices are ignored """ self._set_expected_xcrun_simctl_list('''== Device Types == iPhone 4s (com.apple.CoreSimulator.SimDeviceType.iPhone-4s) == Runtimes == iOS 8.0 (8.0 - 12A465) (com.apple.CoreSimulator.SimRuntime.iOS-8-0) iOS 8.0 Internal (8.0 - Unknown) (com.apple.CoreSimulator.SimRuntime.iOS-8-0-Internal) (unavailable, runtime path not found) == Devices == -- iOS 8.0 -- iPhone 4s (271BBEAC-1826-4CE1-B3AF-83F35CDD1D82) (Shutdown) -- iOS 8.0 Internal -- -- Unavailable: com.apple.CoreSimulator.SimRuntime.iOS-8-1 -- iPhone 4s (08C0542B-65F7-46E8-B203-CB4055207BC8) (Shutdown) (unavailable, runtime profile not found) -- Unavailable: com.apple.CoreSimulator.SimRuntime.iOS-8-2 -- iPhone 4s (A36F7432-0AF5-49C4-A261-C44383992597) (Shutdown) (unavailable, runtime profile not found) ''') simulator = Simulator(host=self._host) self.assertEqual(1, len(simulator.device_types)) device_type_iphone_4s = simulator.device_types[0] self.assertEqual('iPhone 4s', device_type_iphone_4s.name) self.assertEqual('com.apple.CoreSimulator.SimDeviceType.iPhone-4s', device_type_iphone_4s.identifier) self.assertEqual(2, len(simulator.runtimes)) runtime_ios_8 = simulator.runtimes[0] self.assertEqual('com.apple.CoreSimulator.SimRuntime.iOS-8-0', runtime_ios_8.identifier) self.assertEqual(True, runtime_ios_8.available) self.assertEqual(False, runtime_ios_8.is_internal_runtime) self.assertEqual(tuple([8, 0]), runtime_ios_8.version) self.assertEqual(1, len(runtime_ios_8.devices)) device_iphone_4s = runtime_ios_8.devices[0] self.assertEqual('iPhone 4s', device_iphone_4s.name) self.assertEqual('271BBEAC-1826-4CE1-B3AF-83F35CDD1D82', device_iphone_4s.udid) self.assertEqual(True, device_iphone_4s.available) self.assertEqual(runtime_ios_8, device_iphone_4s.runtime) runtime_ios_8_internal = simulator.runtimes[1] self.assertEqual('com.apple.CoreSimulator.SimRuntime.iOS-8-0-Internal', runtime_ios_8_internal.identifier) self.assertEqual(False, runtime_ios_8_internal.available) self.assertEqual(True, runtime_ios_8_internal.is_internal_runtime) self.assertEqual(tuple([8, 0]), runtime_ios_8_internal.version) self.assertEqual(0, len(runtime_ios_8_internal.devices))
def __init__(self, host, port_name, **kwargs): super(IOSSimulatorPort, self).__init__(host, port_name, **kwargs) optional_device_class = self.get_option('device_class') self._device_class = optional_device_class if optional_device_class else self.DEFAULT_DEVICE_CLASS _log.debug('IOSSimulatorPort _device_class is %s', self._device_class) if not IOSSimulatorPort._CURRENT_DEVICE: IOSSimulatorPort._CURRENT_DEVICE = Device(Simulator(host).current_device()) self._current_device = IOSSimulatorPort._CURRENT_DEVICE if not self._current_device: self.set_option('dedicated_simulators', True) if not self.get_option('dedicated_simulators'): if self.get_option('child_processes') > 1: _log.warn('Cannot have more than one child process when using a running simulator. Setting child_processes to 1.') self.set_option('child_processes', 1)
def __init__(self, host, port_name, **kwargs): DarwinPort.__init__(self, host, port_name, **kwargs) self._test_runner_process_constructor = SimulatorProcess optional_device_class = self.get_option('device_class') self._printing_cmd_line = False self._device_class = optional_device_class if optional_device_class else self.DEFAULT_DEVICE_CLASS _log.debug('IOSSimulatorPort _device_class is %s', self._device_class) self._current_device = Simulator(host).current_device() if not self._current_device: self.set_option('dedicated_simulators', True) if not self.get_option('dedicated_simulators'): if self.get_option('child_processes') > 1: _log.warn( 'Cannot have more than one child process when using a running simulator. Setting child_processes to 1.' ) self.set_option('child_processes', 1)
def check_sys_deps(self, needs_http): if not self.simulator_runtime.available: _log.error( 'The iOS Simulator runtime with identifier "{0}" cannot be used because it is unavailable.'.format( self.simulator_runtime.identifier ) ) return False for i in xrange(self.child_processes()): # FIXME: This creates the devices sequentially, doing this in parallel can improve performance. testing_device = self.testing_device(i) _log.debug("Verifying Simulator{0} with UDID {1}.".format(i, testing_device.udid)) # FIXME: This is very slow, especially for mulitple simulators, we probably do not need # this checking as we are re-creating new simulator apps and devices in every run. if not Simulator.check_simulator_device_and_erase_if_needed(self.host, testing_device.udid): _log.error("Unable to boot the simulator device with UDID {0}.".format(testing_device.udid)) return False return super(IOSSimulatorPort, self).check_sys_deps(needs_http)
def testing_device(self, number): return Simulator().lookup_or_create_device(self.simulator_device_type.name + ' WebKit Tester' + str(number), self.simulator_device_type, self.simulator_runtime)
def _create_device(self, number): return Simulator.create_device(number, self.simulator_device_type(), self.simulator_runtime)
def _remove_device(self, number): Simulator.remove_device(number)
def state(self): """ :returns: The current state of the device. :rtype: Simulator.DeviceState """ return Simulator.device_state(self.udid)
def _testing_device(self, number): return Simulator.device_number(number)
def path(self): """ :returns: The filesystem path that contains the simulator device's data. :rtype: str """ return Simulator.device_directory(self.udid)
def test_simulator_device_types(self): """ Tests that valid `xcrun simctl list` output is parsed as expected """ self._set_expected_xcrun_simctl_list('''== Device Types == iPhone 4s (com.apple.CoreSimulator.SimDeviceType.iPhone-4s) iPhone 5 (com.apple.CoreSimulator.SimDeviceType.iPhone-5) iPhone 5s (com.apple.CoreSimulator.SimDeviceType.iPhone-5s) iPhone 6 Plus (com.apple.CoreSimulator.SimDeviceType.iPhone-6-Plus) iPhone 6 (com.apple.CoreSimulator.SimDeviceType.iPhone-6) iPad 2 (com.apple.CoreSimulator.SimDeviceType.iPad-2) iPad Retina (com.apple.CoreSimulator.SimDeviceType.iPad-Retina) iPad Air (com.apple.CoreSimulator.SimDeviceType.iPad-Air) Apple TV 1080p (com.apple.CoreSimulator.SimDeviceType.Apple-TV-1080p) Apple Watch - 38mm (com.apple.CoreSimulator.SimDeviceType.Apple-Watch-38mm) Apple Watch - 42mm (com.apple.CoreSimulator.SimDeviceType.Apple-Watch-42mm) == Runtimes == iOS 8.0 (8.0 - 12A465) (com.apple.CoreSimulator.SimRuntime.iOS-8-0) iOS 8.0 Internal (8.0 - Unknown) (com.apple.CoreSimulator.SimRuntime.iOS-8-0-Internal) (unavailable, runtime path not found) iOS 8.4 (8.4.1 - 12H321) (com.apple.CoreSimulator.SimRuntime.iOS-8-4) tvOS 9.0 (9.0 - 13T5347l) (com.apple.CoreSimulator.SimRuntime.tvOS-9-0) watchOS 2.0 (2.0 - 13S343) (com.apple.CoreSimulator.SimRuntime.watchOS-2-0) == Devices == -- iOS 8.0 -- iPhone 4s (68D9A792-E3A9-462B-B211-762C6A5D3779) (Shutdown) iPhone 5 (1C3767FF-C268-4961-B6DA-F4F75E99EF5D) (Shutdown) iPhone 5s (2A1CB363-9A09-4438-B9BE-9C42BD208F72) (Shutdown) iPhone 5s WebKit Tester (79BA9206-E0B6-4D0E-B0E8-A88E2D45515D) (Booted) iPhone 6 Plus (7F8039BE-D4A0-4245-9D56-AF94413FD6F5) (Shutdown) iPhone 6 (7BF9F835-0CEA-4EE3-BD15-A62BD9F4B691) (Shutdown) iPad 2 (2967C54F-A499-4043-A82C-8C1F5ADBB4A9) (Shutdown) iPad Retina (733FC71E-22F4-4077-BF79-25C27EA881FC) (Shutdown) iPad Air (67266841-82F3-4545-AED6-568B117E41A8) (Shutdown) -- iOS 8.0 Internal -- -- tvOS 9.0 -- Apple TV 1080p (55281ABE-9C27-438B-AD50-C540D7BC4BAC) (Shutdown) -- watchOS 2.0 -- Apple Watch - 38mm (00138CD2-D30C-4380-A30E-A70B88E1A3C5) (Shutdown) Apple Watch - 42mm (186AD85E-9BE5-4734-BC33-DF50484AAFF0) (Shutdown) ''') simulator = Simulator(host=self._host) self.assertEqual(11, len(simulator.device_types)) device_type_iphone_4s = simulator.device_types[0] self.assertEqual('iPhone 4s', device_type_iphone_4s.name) self.assertEqual('com.apple.CoreSimulator.SimDeviceType.iPhone-4s', device_type_iphone_4s.identifier) device_type_iphone_5 = simulator.device_types[1] self.assertEqual('iPhone 5', device_type_iphone_5.name) self.assertEqual('com.apple.CoreSimulator.SimDeviceType.iPhone-5', device_type_iphone_5.identifier) device_type_iphone_5s = simulator.device_types[2] self.assertEqual('iPhone 5s', device_type_iphone_5s.name) self.assertEqual('com.apple.CoreSimulator.SimDeviceType.iPhone-5s', device_type_iphone_5s.identifier) device_type_iphone_6_plus = simulator.device_types[3] self.assertEqual('iPhone 6 Plus', device_type_iphone_6_plus.name) self.assertEqual('com.apple.CoreSimulator.SimDeviceType.iPhone-6-Plus', device_type_iphone_6_plus.identifier) device_type_iphone_6 = simulator.device_types[4] self.assertEqual('iPhone 6', device_type_iphone_6.name) self.assertEqual('com.apple.CoreSimulator.SimDeviceType.iPhone-6', device_type_iphone_6.identifier) device_type_ipad_2 = simulator.device_types[5] self.assertEqual('iPad 2', device_type_ipad_2.name) self.assertEqual('com.apple.CoreSimulator.SimDeviceType.iPad-2', device_type_ipad_2.identifier) device_type_ipad_retina = simulator.device_types[6] self.assertEqual('iPad Retina', device_type_ipad_retina.name) self.assertEqual('com.apple.CoreSimulator.SimDeviceType.iPad-Retina', device_type_ipad_retina.identifier) device_type_ipad_air = simulator.device_types[7] self.assertEqual('iPad Air', device_type_ipad_air.name) self.assertEqual('com.apple.CoreSimulator.SimDeviceType.iPad-Air', device_type_ipad_air.identifier) device_type_apple_tv_1080p = simulator.device_types[8] self.assertEqual('Apple TV 1080p', device_type_apple_tv_1080p.name) self.assertEqual( 'com.apple.CoreSimulator.SimDeviceType.Apple-TV-1080p', device_type_apple_tv_1080p.identifier) device_type_apple_watch_38mm = simulator.device_types[9] self.assertEqual('Apple Watch - 38mm', device_type_apple_watch_38mm.name) self.assertEqual( 'com.apple.CoreSimulator.SimDeviceType.Apple-Watch-38mm', device_type_apple_watch_38mm.identifier) device_type_apple_watch_42mm = simulator.device_types[10] self.assertEqual('Apple Watch - 42mm', device_type_apple_watch_42mm.name) self.assertEqual( 'com.apple.CoreSimulator.SimDeviceType.Apple-Watch-42mm', device_type_apple_watch_42mm.identifier) self.assertEqual(5, len(simulator.runtimes)) runtime_ios_8 = simulator.runtimes[0] self.assertEqual('com.apple.CoreSimulator.SimRuntime.iOS-8-0', runtime_ios_8.identifier) self.assertEqual(True, runtime_ios_8.available) self.assertEqual(False, runtime_ios_8.is_internal_runtime) self.assertEqual(tuple([8, 0]), runtime_ios_8.version) self.assertEqual(9, len(runtime_ios_8.devices)) device_iphone_4s = runtime_ios_8.devices[0] self.assertEqual('iPhone 4s', device_iphone_4s.name) self.assertEqual('68D9A792-E3A9-462B-B211-762C6A5D3779', device_iphone_4s.udid) self.assertEqual(True, device_iphone_4s.available) self.assertEqual(runtime_ios_8, device_iphone_4s.runtime) device_iphone_5 = runtime_ios_8.devices[1] self.assertEqual('iPhone 5', device_iphone_5.name) self.assertEqual('1C3767FF-C268-4961-B6DA-F4F75E99EF5D', device_iphone_5.udid) self.assertEqual(True, device_iphone_5.available) self.assertEqual(runtime_ios_8, device_iphone_5.runtime) device_iphone_5s = runtime_ios_8.devices[2] self.assertEqual('iPhone 5s', device_iphone_5s.name) self.assertEqual('2A1CB363-9A09-4438-B9BE-9C42BD208F72', device_iphone_5s.udid) self.assertEqual(True, device_iphone_5s.available) self.assertEqual(runtime_ios_8, device_iphone_5s.runtime) device_iphone_5s_webkit_tester = runtime_ios_8.devices[3] self.assertEqual('iPhone 5s WebKit Tester', device_iphone_5s_webkit_tester.name) self.assertEqual('79BA9206-E0B6-4D0E-B0E8-A88E2D45515D', device_iphone_5s_webkit_tester.udid) self.assertEqual(True, device_iphone_5s_webkit_tester.available) self.assertEqual(runtime_ios_8, device_iphone_5s_webkit_tester.runtime) device_iphone_6_plus = runtime_ios_8.devices[4] self.assertEqual('iPhone 6 Plus', device_iphone_6_plus.name) self.assertEqual('7F8039BE-D4A0-4245-9D56-AF94413FD6F5', device_iphone_6_plus.udid) self.assertEqual(True, device_iphone_6_plus.available) self.assertEqual(runtime_ios_8, device_iphone_6_plus.runtime) device_iphone_6 = runtime_ios_8.devices[5] self.assertEqual('iPhone 6', device_iphone_6.name) self.assertEqual('7BF9F835-0CEA-4EE3-BD15-A62BD9F4B691', device_iphone_6.udid) self.assertEqual(True, device_iphone_6.available) self.assertEqual(runtime_ios_8, device_iphone_6.runtime) device_ipad_2 = runtime_ios_8.devices[6] self.assertEqual('iPad 2', device_ipad_2.name) self.assertEqual('2967C54F-A499-4043-A82C-8C1F5ADBB4A9', device_ipad_2.udid) self.assertEqual(True, device_ipad_2.available) self.assertEqual(runtime_ios_8, device_ipad_2.runtime) device_ipad_retina = runtime_ios_8.devices[7] self.assertEqual('iPad Retina', device_ipad_retina.name) self.assertEqual('733FC71E-22F4-4077-BF79-25C27EA881FC', device_ipad_retina.udid) self.assertEqual(True, device_ipad_retina.available) self.assertEqual(runtime_ios_8, device_ipad_retina.runtime) device_ipad_air = runtime_ios_8.devices[8] self.assertEqual('iPad Air', device_ipad_air.name) self.assertEqual('67266841-82F3-4545-AED6-568B117E41A8', device_ipad_air.udid) self.assertEqual(True, device_ipad_air.available) self.assertEqual(runtime_ios_8, device_ipad_air.runtime) runtime_ios_8_internal = simulator.runtimes[1] self.assertEqual('com.apple.CoreSimulator.SimRuntime.iOS-8-0-Internal', runtime_ios_8_internal.identifier) self.assertEqual(False, runtime_ios_8_internal.available) self.assertEqual(True, runtime_ios_8_internal.is_internal_runtime) self.assertEqual(tuple([8, 0]), runtime_ios_8_internal.version) self.assertEqual(0, len(runtime_ios_8_internal.devices)) runtime_ios_8_4 = simulator.runtimes[2] self.assertEqual('com.apple.CoreSimulator.SimRuntime.iOS-8-4', runtime_ios_8_4.identifier) self.assertEqual(True, runtime_ios_8_4.available) self.assertEqual(False, runtime_ios_8_4.is_internal_runtime) self.assertEqual(tuple([8, 4]), runtime_ios_8_4.version) self.assertEqual(0, len(runtime_ios_8_4.devices)) runtime_tvos_9 = simulator.runtimes[3] self.assertEqual('com.apple.CoreSimulator.SimRuntime.tvOS-9-0', runtime_tvos_9.identifier) self.assertEqual(True, runtime_tvos_9.available) self.assertEqual(False, runtime_tvos_9.is_internal_runtime) self.assertEqual(tuple([9, 0]), runtime_tvos_9.version) self.assertEqual(1, len(runtime_tvos_9.devices)) device_apple_tv_1080p = runtime_tvos_9.devices[0] self.assertEqual('Apple TV 1080p', device_apple_tv_1080p.name) self.assertEqual('55281ABE-9C27-438B-AD50-C540D7BC4BAC', device_apple_tv_1080p.udid) self.assertEqual(True, device_apple_tv_1080p.available) self.assertEqual(runtime_tvos_9, device_apple_tv_1080p.runtime) runtime_watchos_2 = simulator.runtimes[4] self.assertEqual('com.apple.CoreSimulator.SimRuntime.watchOS-2-0', runtime_watchos_2.identifier) self.assertEqual(True, runtime_watchos_2.available) self.assertEqual(False, runtime_watchos_2.is_internal_runtime) self.assertEqual(tuple([2, 0]), runtime_watchos_2.version) self.assertEqual(2, len(runtime_watchos_2.devices)) device_apple_watch_38mm = runtime_watchos_2.devices[0] self.assertEqual('Apple Watch - 38mm', device_apple_watch_38mm.name) self.assertEqual('00138CD2-D30C-4380-A30E-A70B88E1A3C5', device_apple_watch_38mm.udid) self.assertEqual(True, device_apple_watch_38mm.available) self.assertEqual(runtime_watchos_2, device_apple_watch_38mm.runtime) device_apple_watch_42mm = runtime_watchos_2.devices[1] self.assertEqual('Apple Watch - 42mm', device_apple_watch_42mm.name) self.assertEqual('186AD85E-9BE5-4734-BC33-DF50484AAFF0', device_apple_watch_42mm.udid) self.assertEqual(True, device_apple_watch_42mm.available) self.assertEqual(runtime_watchos_2, device_apple_watch_42mm.runtime)
def test_simulator_device_types(self): """ Tests that valid `xcrun simctl list` output is parsed as expected """ self._set_expected_xcrun_simctl_list('''== Device Types == iPhone 4s (com.apple.CoreSimulator.SimDeviceType.iPhone-4s) iPhone 5 (com.apple.CoreSimulator.SimDeviceType.iPhone-5) iPhone 5s (com.apple.CoreSimulator.SimDeviceType.iPhone-5s) iPhone 6 Plus (com.apple.CoreSimulator.SimDeviceType.iPhone-6-Plus) iPhone 6 (com.apple.CoreSimulator.SimDeviceType.iPhone-6) iPad 2 (com.apple.CoreSimulator.SimDeviceType.iPad-2) iPad Retina (com.apple.CoreSimulator.SimDeviceType.iPad-Retina) iPad Air (com.apple.CoreSimulator.SimDeviceType.iPad-Air) == Runtimes == iOS 8.0 (8.0 - 12A465) (com.apple.CoreSimulator.SimRuntime.iOS-8-0) iOS 8.0 Internal (8.0 - Unknown) (com.apple.CoreSimulator.SimRuntime.iOS-8-0-Internal) (unavailable, runtime path not found) == Devices == -- iOS 8.0 -- iPhone 4s (68D9A792-E3A9-462B-B211-762C6A5D3779) (Shutdown) iPhone 5 (1C3767FF-C268-4961-B6DA-F4F75E99EF5D) (Shutdown) iPhone 5s (2A1CB363-9A09-4438-B9BE-9C42BD208F72) (Shutdown) iPhone 5s WebKit Tester (79BA9206-E0B6-4D0E-B0E8-A88E2D45515D) (Booted) iPhone 6 Plus (7F8039BE-D4A0-4245-9D56-AF94413FD6F5) (Shutdown) iPhone 6 (7BF9F835-0CEA-4EE3-BD15-A62BD9F4B691) (Shutdown) iPad 2 (2967C54F-A499-4043-A82C-8C1F5ADBB4A9) (Shutdown) iPad Retina (733FC71E-22F4-4077-BF79-25C27EA881FC) (Shutdown) iPad Air (67266841-82F3-4545-AED6-568B117E41A8) (Shutdown) -- iOS 8.0 Internal -- ''') simulator = Simulator(host=self._host) self.assertEqual(8, len(simulator.device_types)) device_type_iphone_4s = simulator.device_types[0] self.assertEqual('iPhone 4s', device_type_iphone_4s.name) self.assertEqual('com.apple.CoreSimulator.SimDeviceType.iPhone-4s', device_type_iphone_4s.identifier) device_type_iphone_5 = simulator.device_types[1] self.assertEqual('iPhone 5', device_type_iphone_5.name) self.assertEqual('com.apple.CoreSimulator.SimDeviceType.iPhone-5', device_type_iphone_5.identifier) device_type_iphone_5s = simulator.device_types[2] self.assertEqual('iPhone 5s', device_type_iphone_5s.name) self.assertEqual('com.apple.CoreSimulator.SimDeviceType.iPhone-5s', device_type_iphone_5s.identifier) device_type_iphone_6_plus = simulator.device_types[3] self.assertEqual('iPhone 6 Plus', device_type_iphone_6_plus.name) self.assertEqual('com.apple.CoreSimulator.SimDeviceType.iPhone-6-Plus', device_type_iphone_6_plus.identifier) device_type_iphone_6 = simulator.device_types[4] self.assertEqual('iPhone 6', device_type_iphone_6.name) self.assertEqual('com.apple.CoreSimulator.SimDeviceType.iPhone-6', device_type_iphone_6.identifier) device_type_ipad_2 = simulator.device_types[5] self.assertEqual('iPad 2', device_type_ipad_2.name) self.assertEqual('com.apple.CoreSimulator.SimDeviceType.iPad-2', device_type_ipad_2.identifier) device_type_ipad_retina = simulator.device_types[6] self.assertEqual('iPad Retina', device_type_ipad_retina.name) self.assertEqual('com.apple.CoreSimulator.SimDeviceType.iPad-Retina', device_type_ipad_retina.identifier) device_type_ipad_air = simulator.device_types[7] self.assertEqual('iPad Air', device_type_ipad_air.name) self.assertEqual('com.apple.CoreSimulator.SimDeviceType.iPad-Air', device_type_ipad_air.identifier) self.assertEqual(2, len(simulator.runtimes)) runtime_ios_8 = simulator.runtimes[0] self.assertEqual('com.apple.CoreSimulator.SimRuntime.iOS-8-0', runtime_ios_8.identifier) self.assertEqual(True, runtime_ios_8.available) self.assertEqual(False, runtime_ios_8.is_internal_runtime) self.assertEqual(tuple([8, 0]), runtime_ios_8.version) self.assertEqual(9, len(runtime_ios_8.devices)) device_iphone_4s = runtime_ios_8.devices[0] self.assertEqual('iPhone 4s', device_iphone_4s.name) self.assertEqual('68D9A792-E3A9-462B-B211-762C6A5D3779', device_iphone_4s.udid) self.assertEqual(True, device_iphone_4s.available) self.assertEqual(runtime_ios_8, device_iphone_4s.runtime) device_iphone_5 = runtime_ios_8.devices[1] self.assertEqual('iPhone 5', device_iphone_5.name) self.assertEqual('1C3767FF-C268-4961-B6DA-F4F75E99EF5D', device_iphone_5.udid) self.assertEqual(True, device_iphone_5.available) self.assertEqual(runtime_ios_8, device_iphone_5.runtime) device_iphone_5s = runtime_ios_8.devices[2] self.assertEqual('iPhone 5s', device_iphone_5s.name) self.assertEqual('2A1CB363-9A09-4438-B9BE-9C42BD208F72', device_iphone_5s.udid) self.assertEqual(True, device_iphone_5s.available) self.assertEqual(runtime_ios_8, device_iphone_5s.runtime) device_iphone_5s_webkit_tester = runtime_ios_8.devices[3] self.assertEqual('iPhone 5s WebKit Tester', device_iphone_5s_webkit_tester.name) self.assertEqual('79BA9206-E0B6-4D0E-B0E8-A88E2D45515D', device_iphone_5s_webkit_tester.udid) self.assertEqual(True, device_iphone_5s_webkit_tester.available) self.assertEqual(runtime_ios_8, device_iphone_5s_webkit_tester.runtime) device_iphone_6_plus = runtime_ios_8.devices[4] self.assertEqual('iPhone 6 Plus', device_iphone_6_plus.name) self.assertEqual('7F8039BE-D4A0-4245-9D56-AF94413FD6F5', device_iphone_6_plus.udid) self.assertEqual(True, device_iphone_6_plus.available) self.assertEqual(runtime_ios_8, device_iphone_6_plus.runtime) device_iphone_6 = runtime_ios_8.devices[5] self.assertEqual('iPhone 6', device_iphone_6.name) self.assertEqual('7BF9F835-0CEA-4EE3-BD15-A62BD9F4B691', device_iphone_6.udid) self.assertEqual(True, device_iphone_6.available) self.assertEqual(runtime_ios_8, device_iphone_6.runtime) device_ipad_2 = runtime_ios_8.devices[6] self.assertEqual('iPad 2', device_ipad_2.name) self.assertEqual('2967C54F-A499-4043-A82C-8C1F5ADBB4A9', device_ipad_2.udid) self.assertEqual(True, device_ipad_2.available) self.assertEqual(runtime_ios_8, device_ipad_2.runtime) device_ipad_retina = runtime_ios_8.devices[7] self.assertEqual('iPad Retina', device_ipad_retina.name) self.assertEqual('733FC71E-22F4-4077-BF79-25C27EA881FC', device_ipad_retina.udid) self.assertEqual(True, device_ipad_retina.available) self.assertEqual(runtime_ios_8, device_ipad_retina.runtime) device_ipad_air = runtime_ios_8.devices[8] self.assertEqual('iPad Air', device_ipad_air.name) self.assertEqual('67266841-82F3-4545-AED6-568B117E41A8', device_ipad_air.udid) self.assertEqual(True, device_ipad_air.available) self.assertEqual(runtime_ios_8, device_ipad_air.runtime) runtime_ios_8_internal = simulator.runtimes[1] self.assertEqual('com.apple.CoreSimulator.SimRuntime.iOS-8-0-Internal', runtime_ios_8_internal.identifier) self.assertEqual(False, runtime_ios_8_internal.available) self.assertEqual(True, runtime_ios_8_internal.is_internal_runtime) self.assertEqual(tuple([8, 0]), runtime_ios_8_internal.version) self.assertEqual(0, len(runtime_ios_8_internal.devices))