def test_swapping_devices(self): SimulatedDeviceTest.reset_simulated_device_manager() host = SimulatedDeviceTest.mock_host_for_simctl() SimulatedDeviceManager.available_devices(host) # We won't test the creation and deletion of simulators, only managing existing sims SimulatedDeviceTest.change_state_to(SimulatedDeviceManager.device_by_filter(lambda device: device.platform_device.device_type == DeviceType.from_string('iPhone 8'), host)[0], SimulatedDevice.DeviceState.BOOTED) SimulatedDeviceTest.change_state_to(SimulatedDeviceManager.device_by_filter(lambda device: device.platform_device.device_type == DeviceType.from_string('iPhone X'), host)[0], SimulatedDevice.DeviceState.BOOTED) SimulatedDeviceManager.initialize_devices(DeviceRequest(DeviceType.from_string('iPhone 8')), host=host) self.assertEquals(1, len(SimulatedDeviceManager.INITIALIZED_DEVICES)) self.assertEquals('17104B4F-E77D-4019-98E6-621FE3CC3653', SimulatedDeviceManager.INITIALIZED_DEVICES[0].udid) self.assertEquals(SimulatedDevice.DeviceState.BOOTED, SimulatedDeviceManager.INITIALIZED_DEVICES[0].platform_device.state()) # Now swap for the X SimulatedDeviceTest.change_state_to(SimulatedDeviceManager.INITIALIZED_DEVICES[0], SimulatedDevice.DeviceState.SHUT_DOWN) SimulatedDeviceManager.swap(SimulatedDeviceManager.INITIALIZED_DEVICES[0], DeviceRequest(DeviceType.from_string('iPhone X')), host) self.assertEquals(1, len(SimulatedDeviceManager.INITIALIZED_DEVICES)) self.assertEquals('4E6E7393-C4E3-4323-AA8B-4A42A45AE7B8', SimulatedDeviceManager.INITIALIZED_DEVICES[0].udid) self.assertEquals(SimulatedDevice.DeviceState.BOOTED, SimulatedDeviceManager.INITIALIZED_DEVICES[0].platform_device.state()) SimulatedDeviceTest.change_state_to(SimulatedDeviceManager.INITIALIZED_DEVICES[0], SimulatedDevice.DeviceState.SHUT_DOWN) SimulatedDeviceManager.tear_down(host) self.assertIsNone(SimulatedDeviceManager.INITIALIZED_DEVICES)
def _initialize_devices(self): if 'simulator' in self._port.port_name: SimulatedDeviceManager.initialize_devices(DeviceRequest( self._port.DEVICE_TYPE, allow_incomplete_match=True), self.host, simulator_ui=False) elif 'device' in self._port.port_name: raise RuntimeError( 'Running api tests on {} is not supported'.format( self._port.port_name))
def test_existing_simulator(self): SimulatedDeviceTest.reset_simulated_device_manager() host = SimulatedDeviceTest.mock_host_for_simctl() SimulatedDeviceManager.available_devices(host) SimulatedDeviceManager.initialize_devices(DeviceRequest(DeviceType.from_string('iPhone', Version(11))), host=host) self.assertEquals(1, len(SimulatedDeviceManager.INITIALIZED_DEVICES)) self.assertEquals('34FB476C-6FA0-43C8-8945-1BD7A4EBF0DE', SimulatedDeviceManager.INITIALIZED_DEVICES[0].udid) self.assertEquals(SimulatedDevice.DeviceState.BOOTED, SimulatedDeviceManager.INITIALIZED_DEVICES[0].platform_device.state()) SimulatedDeviceManager.tear_down(host) self.assertIsNone(SimulatedDeviceManager.INITIALIZED_DEVICES)
def _create_devices(self, device_class): self._set_device_class(device_class) device_type = DeviceType.from_string(self._device_class, self.ios_version()) _log.debug('') _log.debug('creating devices for {}'.format(device_type)) request = DeviceRequest( device_type, use_booted_simulator=not self.get_option('dedicated_simulators', False), use_existing_simulator=False, allow_incomplete_match=True, ) SimulatedDeviceManager.initialize_devices([request] * self.child_processes(), self.host)
def setup_test_run(self, device_type=None): if not self.DEVICE_MANAGER: raise RuntimeError(self.NO_DEVICE_MANAGER) device_type = self._device_type_with_version(device_type) _log.debug('\nCreating devices for {}'.format(device_type)) request = DeviceRequest( device_type, use_booted_simulator=not self.get_option('dedicated_simulators', False), use_existing_simulator=False, allow_incomplete_match=self.get_option('force'), ) self.DEVICE_MANAGER.initialize_devices( [request] * self.child_processes(), self.host, layout_test_dir=self.layout_tests_dir(), pin=self.get_option('pin', None), use_nfs=self.get_option('use_nfs', True), reboot=self.get_option('reboot', False), ) if not self.devices(): raise RuntimeError('No devices are available for testing') if len(self.DEVICE_MANAGER.INITIALIZED_DEVICES) < self.child_processes( ): raise RuntimeError( 'To few connected devices for {} processes'.format( self.child_processes())) self._install() for i in xrange(self.child_processes()): host = self.target_host(i) host.prepare_for_testing( self.ports_to_forward(), self.app_identifier_from_bundle(self._path_to_driver()), self.layout_tests_dir(), ) self._crash_logs_to_skip_for_host[ host] = host.filesystem.files_under(self.path_to_crash_logs())