예제 #1
0
 def _RunSimulatorTest(args):
     """The function of running test with new simulator."""
     with xctest_session.XctestSession(
             sdk=ios_constants.SDK.IPHONESIMULATOR,
             device_arch=ios_constants.ARCH.X86_64,
             work_dir=args.work_dir,
             output_dir=args.output_dir) as session:
         simulator_id, _, os_version, _ = simulator_util.CreateNewSimulator(
             device_type=args.device_type,
             os_version=args.os_version,
             name_prefix=args.new_simulator_name_prefix)
         simulator_obj = simulator_util.Simulator(simulator_id)
         hostless = args.app_under_test_path is None
         try:
             if not hostless:
                 simulator_obj.Boot()
             session.Prepare(app_under_test=args.app_under_test_path,
                             test_bundle=args.test_bundle_path,
                             xctestrun_file_path=args.xctestrun,
                             test_type=args.test_type,
                             signing_options=_GetJson(
                                 args.signing_options_json_path))
             session.SetLaunchOptions(
                 _GetJson(args.launch_options_json_path))
             if not hostless:
                 try:
                     simulator_obj.BootStatus().wait(timeout=60)
                 except subprocess.TimeoutExpired:
                     logging.warning(
                         'The simulator %s could not be booted in 60s. Will try to run '
                         'test directly.', simulator_id)
             return session.RunTest(simulator_id, os_version=os_version)
         finally:
             simulator_obj.Delete()
예제 #2
0
 def _Test(args):
   """The function of sub command `test`."""
   sdk = _PlatformToSdk(args.platform) if args.platform else _GetSdk(args.id)
   with xctest_session.XctestSession(
       sdk=sdk, work_dir=args.work_dir, output_dir=args.output_dir) as session:
     session.Prepare(
         app_under_test=args.app_under_test_path,
         test_bundle=args.test_bundle_path,
         xctestrun_file_path=args.xctestrun,
         test_type=args.test_type,
         signing_options=_GetJson(args.signing_options_json_path))
     session.SetLaunchOptions(_GetJson(args.launch_options_json_path))
     return session.RunTest(args.id)
예제 #3
0
    def _RunSimulatorTest(args):
        """The function of running test with new simulator."""
        with xctest_session.XctestSession(
                sdk=ios_constants.SDK.IPHONESIMULATOR,
                work_dir=args.work_dir,
                output_dir=args.output_dir) as session:
            session.Prepare(app_under_test=args.app_under_test_path,
                            test_bundle=args.test_bundle_path,
                            xctestrun_file_path=args.xctestrun,
                            test_type=args.test_type,
                            signing_options=_GetJson(
                                args.signing_options_json_path))
            session.SetLaunchOptions(_GetJson(args.launch_options_json_path))

            # In prior of Xcode 9, `xcodebuild test` will launch the Simulator.app
            # process. If there is Simulator.app before running test, it will cause
            # error later.
            if xcode_info_util.GetXcodeVersionNumber() < 900:
                simulator_util.QuitSimulatorApp()
            max_attempts = 3
            reboot_sim = False
            for i in range(max_attempts):
                if not reboot_sim:
                    simulator_id, _, _, _ = simulator_util.CreateNewSimulator(
                        device_type=args.device_type,
                        os_version=args.os_version,
                        name=args.new_simulator_name)
                reboot_sim = False

                try:
                    # Don't use command "{Xcode_developer_dir}Applications/ \
                    # Simulator.app/Contents/MacOS/Simulator" to launch the Simulator.app.
                    # 1) `xcodebuild test` will handle the launch Simulator.
                    # 2) If there are two Simulator.app processes launched by command line
                    # and `xcodebuild test` starts to run on one of Simulator, the another
                    # Simulator.app will popup 'Unable to boot device in current state: \
                    # Booted' dialog and may cause potential error.
                    exit_code = session.RunTest(simulator_id)
                    if i < max_attempts - 1:
                        if exit_code == runner_exit_codes.EXITCODE.NEED_RECREATE_SIM:
                            logging.warning(
                                'Will create a new simulator to retry running test.'
                            )
                            continue
                        if exit_code == runner_exit_codes.EXITCODE.NEED_REBOOT_DEVICE:
                            reboot_sim = True
                            logging.warning(
                                'Will reboot the simulator to retry running test.'
                            )
                            continue
                    return exit_code
                finally:
                    # 1. In prior of Xcode 9, `xcodebuild test` will launch the
                    # Simulator.app process. Quit the Simulator.app to avoid side effect.
                    # 2. Quit Simulator.app can also shutdown the simulator. To make sure
                    # the Simulator state to be SHUTDOWN, still call shutdown command
                    # later.
                    if xcode_info_util.GetXcodeVersionNumber() < 900:
                        simulator_util.QuitSimulatorApp()
                    simulator_obj = simulator_util.Simulator(simulator_id)
                    if reboot_sim:
                        simulator_obj.Shutdown()
                    else:
                        # In Xcode 9+, simctl can delete the Booted simulator.
                        # In prior of Xcode 9, we have to shutdown the simulator first
                        # before deleting it.
                        if xcode_info_util.GetXcodeVersionNumber() < 900:
                            simulator_obj.Shutdown()
                        simulator_obj.Delete()