diff --git a/simulator_control/simulator_util.py b/simulator_control/simulator_util.py index 0f186fe..20b9844 100644 --- a/simulator_control/simulator_util.py +++ b/simulator_control/simulator_util.py @@ -113,13 +113,20 @@ def device_plist_object(self): self._device_plist_object = plist_util.Plist(device_plist_path) return self._device_plist_object - def Boot(self): + def Boot(self, simulator_language=None): """Boots the simulator as asynchronously. + Args: + simulator_language: string, the language of the simulator at startup time, e.g. 'ja'. Returns: A subprocess.Popen object of the boot process. """ RunSimctlCommand(['xcrun', 'simctl', 'boot', self.simulator_id]) + if simulator_language: + RunSimctlCommand(['xcrun', 'simctl', 'spawn', self.simulator_id, + 'defaults', 'write', 'Apple Global Domain', 'AppleLanguages', + '-array', simulator_language]) + RespringAllSimulators() self.WaitUntilStateBooted() logging.info('The simulator %s is booted.', self.simulator_id) @@ -305,7 +312,7 @@ def GetSimulatorState(self): return _SIMULATOR_STATES_MAPPING[state_num] -def CreateNewSimulator(device_type=None, os_version=None, name_prefix=None): +def CreateNewSimulator(device_type=None, os_version=None, name_prefix=None, language=None): """Creates a new simulator according to arguments. If neither device_type nor os_version is given, will use the latest iOS @@ -663,6 +670,13 @@ def QuitSimulatorApp(): stderr=subprocess.STDOUT) +def RespringAllSimulators(): + """Restarts the SpringBoard.app in all booted simulator.""" + subprocess.Popen(['killall', '-HUP', 'SpringBoard'], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) + + def IsAppFailedToLaunchOnSim(sim_sys_log, app_bundle_id=''): """Checks if the app failed to launch on simulator. diff --git a/test_runner/ios_test_runner.py b/test_runner/ios_test_runner.py index c85800d..27307d6 100644 --- a/test_runner/ios_test_runner.py +++ b/test_runner/ios_test_runner.py @@ -191,7 +191,7 @@ def _RunSimulatorTest(args): hostless = args.app_under_test_path is None try: if not hostless: - simulator_obj.Boot() + simulator_obj.Boot(args.simulator_language) session.Prepare( app_under_test=args.app_under_test_path, test_bundle=args.test_bundle_path, @@ -238,6 +238,10 @@ def _SimulatorTest(args): 'The new simulator name will be the value of concatenating name ' 'prefix with simulator type and os version. ' 'E.g., New-iPhone 6 Plus-10.2.') + test_parser.add_argument( + '--simulator_language', + help='The system language of the simulator at creation time, e.g `ja`. ' + 'Note: Do not set this if you create multiple simulators simutaneously.') test_parser.set_defaults(func=_SimulatorTest)