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 test_matching_up_failure(self):
        SimulatedDeviceTest.reset_simulated_device_manager()
        host = SimulatedDeviceTest.mock_host_for_simctl()
        SimulatedDeviceManager.available_devices(host)

        runtime = SimulatedDeviceManager.get_runtime_for_device_type(
            DeviceType.from_string('iphone 5s', Version(9, 4)))
        self.assertEquals(runtime, None)
    def test_matching_up_success(self):
        SimulatedDeviceTest.reset_simulated_device_manager()
        host = SimulatedDeviceTest.mock_host_for_simctl()
        SimulatedDeviceManager.available_devices(host)

        runtime = SimulatedDeviceManager.get_runtime_for_device_type(
            DeviceType.from_string('iphone 5s', Version(9, 2)))
        self.assertEquals(runtime.os_variant, 'iOS')
        self.assertEquals(runtime.version, Version(9, 3))
Exemplo n.º 4
0
 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))
Exemplo n.º 5
0
    def default_child_processes(self):
        def booted_ios_devices_filter(device):
            if not device.platform_device.is_booted_or_booting():
                return False
            return device.platform_device.device_type in DeviceType(software_variant='iOS',
                                                                    software_version=self.ios_version())

        if self.get_option('dedicated_simulators', False):
            num_booted_sims = len(SimulatedDeviceManager.device_by_filter(booted_ios_devices_filter, host=self.host))
            if num_booted_sims:
                return num_booted_sims
        return SimulatedDeviceManager.max_supported_simulators(self.host)
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
 def check_sys_deps(self, needs_http):
     target_device_type = DeviceType(software_variant='iOS', software_version=self.ios_version())
     for device in SimulatedDeviceManager.available_devices(self.host):
         if device.platform_device.device_type in target_device_type:
             return super(IOSSimulatorPort, self).check_sys_deps(needs_http)
     _log.error('No Simulated device matching "{}" defined in Xcode iOS SDK'.format(str(target_device_type)))
     return False
Exemplo n.º 8
0
    def test_no_state_files(self):
        SimulatedDeviceTest.reset_simulated_device_manager()
        host = SimulatedDeviceTest.mock_host_for_simctl()
        host.filesystem = MockFileSystem()
        devices = SimulatedDeviceManager.available_devices(host)

        for device in devices:
            self.assertEquals(SimulatedDevice.DeviceState.SHUT_DOWN,
                              device.state(force_update=True))
    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)
Exemplo n.º 10
0
 def reset_preferences(self):
     SimulatedDeviceManager.tear_down(self.host)
Exemplo n.º 11
0
 def reset_preferences(self):
     _log.debug("reset_preferences")
     SimulatedDeviceManager.tear_down(self.host)
Exemplo n.º 12
0
    def clean_up_test_run(self):
        super(IOSSimulatorPort, self).clean_up_test_run()
        _log.debug("clean_up_test_run")

        SimulatedDeviceManager.tear_down(self.host)
Exemplo n.º 13
0
    def test_available_devices(self):
        SimulatedDeviceTest.reset_simulated_device_manager()
        host = SimulatedDeviceTest.mock_host_for_simctl()
        SimulatedDeviceManager.available_devices(host)

        # There should only be 1 iPhone X, iPhone 8 and iPhone SE
        self.assertEquals(
            1,
            len(
                SimulatedDeviceManager.device_by_filter(
                    lambda device: device.device_type == DeviceType.
                    from_string('iPhone X'), host)))
        self.assertEquals(
            1,
            len(
                SimulatedDeviceManager.device_by_filter(
                    lambda device: device.device_type == DeviceType.
                    from_string('iPhone 8'), host)))

        # There should be 2 5s and 6s
        self.assertEquals(
            2,
            len(
                SimulatedDeviceManager.device_by_filter(
                    lambda device: device.device_type == DeviceType.
                    from_string('iPhone 5s'), host)))
        self.assertEquals(
            2,
            len(
                SimulatedDeviceManager.device_by_filter(
                    lambda device: device.device_type == DeviceType.
                    from_string('iPhone 6s'), host)))

        # 19 iPhones
        self.assertEquals(
            19,
            len(
                SimulatedDeviceManager.device_by_filter(
                    lambda device: device.device_type == DeviceType.
                    from_string('iPhone'), host)))

        # 11 iPads
        self.assertEquals(
            11,
            len(
                SimulatedDeviceManager.device_by_filter(
                    lambda device: device.device_type == DeviceType.
                    from_string('iPad'), host)))

        # 18 Apple watches
        self.assertEquals(
            6,
            len(
                SimulatedDeviceManager.device_by_filter(
                    lambda device: device.device_type == DeviceType.
                    from_string('Apple Watch'), host)))

        # 3 Apple TVs
        self.assertEquals(
            3,
            len(
                SimulatedDeviceManager.device_by_filter(
                    lambda device: device.device_type == DeviceType.
                    from_string('Apple TV'), host)))

        # 18 devices running iOS 11.0
        self.assertEquals(
            18,
            len(
                SimulatedDeviceManager.device_by_filter(
                    lambda device: device.device_type == DeviceType(
                        software_variant='iOS',
                        software_version=Version(11, 0, 1)), host)))

        # 11 iPhones running iOS 11.0
        self.assertEquals(
            11,
            len(
                SimulatedDeviceManager.device_by_filter(
                    lambda device: device.device_type == DeviceType(
                        hardware_family='iPhone',
                        software_version=Version(11, 0, 1)), host)))

        # 1 device running iOS 12
        self.assertEquals(
            1,
            len(
                SimulatedDeviceManager.device_by_filter(
                    lambda device: device.device_type == DeviceType(
                        software_variant='iOS',
                        software_version=Version(12, 0, 0)), host)))