Пример #1
0
    def RunTest(self, device_id, os_version=None):
        """Runs test on the target device with the given device_id.

    Args:
      device_id: string, id of the device.
      os_version: string, OS version of the device.

    Returns:
      A value of type runner_exit_codes.EXITCODE.

    Raises:
      XcodebuildTestError: when the XctestSession.Prepare has not been called.
    """
        if not self._prepared:
            raise ios_errors.XcodebuildTestError(
                'The session has not been prepared. Please call '
                'XctestSession.Prepare first.')

        if self._xctestrun_obj:
            result_bundle_path = os.path.join(self._output_dir,
                                              'test.xcresult')
            exit_code = self._xctestrun_obj.Run(
                device_id,
                self._sdk,
                self._output_dir,
                self._startup_timeout_sec,
                self._destination_timeout_sec,
                os_version=os_version,
                result_bundle_path=result_bundle_path)
            # The xcresult only contains raw data in Xcode 11 or later.
            if xcode_info_util.GetXcodeVersionNumber() >= 1100:
                expose_xcresult = os.path.join(self._output_dir,
                                               'ExposeXcresult')
                try:
                    xcresult_util.ExpoesXcresult(result_bundle_path,
                                                 expose_xcresult)
                    if not self._keep_xcresult_data:
                        shutil.rmtree(result_bundle_path)
                except subprocess.CalledProcessError as e:
                    logging.warning(e.output)
            return exit_code
        elif self._logic_test_bundle:
            return logic_test_util.RunLogicTestOnSim(device_id,
                                                     self._logic_test_bundle,
                                                     self._logic_test_env_vars,
                                                     self._logic_test_args,
                                                     self._logic_tests_to_run,
                                                     os_version=os_version)
        else:
            raise ios_errors.XcodebuildTestError('Unexpected runtime error.')
    def RunTest(self, device_id):
        """Runs test on the target device with the given device_id.

    Args:
      device_id: string, id of the device.

    Returns:
      A value of type runner_exit_codes.EXITCODE.

    Raises:
      XcodebuildTestError: when the XctestSession.Prepare has not been called.
    """
        if not self._prepared:
            raise ios_errors.XcodebuildTestError(
                'The session has not been prepared. Please call '
                'XctestSession.Prepare first.')

        if self._xctestrun_obj:
            exit_code = self._xctestrun_obj.Run(device_id, self._sdk,
                                                self._output_dir,
                                                self._startup_timeout_sec,
                                                self._destination_timeout_sec)
            for test_summaries_path in test_summaries_util.GetTestSummariesPaths(
                    self._output_dir):
                try:
                    test_summaries_util.ParseTestSummaries(
                        test_summaries_path,
                        os.path.join(self._output_dir,
                                     'Logs/Test/Attachments'),
                        True if self._disable_uitest_auto_screenshots else
                        exit_code == runner_exit_codes.EXITCODE.SUCCEEDED)
                except ios_errors.PlistError as e:
                    logging.warning('Failed to parse test summaries %s: %s',
                                    test_summaries_path, str(e))
            return exit_code
        elif self._dummy_project_obj:
            return self._dummy_project_obj.RunXcTest(device_id, self._work_dir,
                                                     self._output_dir,
                                                     self._startup_timeout_sec)
        elif self._logic_test_bundle:
            return logic_test_util.RunLogicTestOnSim(device_id,
                                                     self._logic_test_bundle,
                                                     self._logic_test_env_vars,
                                                     self._logic_test_args,
                                                     self._logic_tests_to_run)
        else:
            raise ios_errors.XcodebuildTestError('Unexpected runtime error.')
Пример #3
0
    def RunTest(self, device_id, os_version=None):
        """Runs test on the target device with the given device_id.

    Args:
      device_id: string, id of the device.
      os_version: string, OS version of the device.

    Returns:
      A value of type runner_exit_codes.EXITCODE.

    Raises:
      XcodebuildTestError: when the XctestSession.Prepare has not been called.
    """
        if not self._prepared:
            raise ios_errors.XcodebuildTestError(
                'The session has not been prepared. Please call '
                'XctestSession.Prepare first.')

        if self._xctestrun_obj:
            exit_code = self._xctestrun_obj.Run(device_id,
                                                self._sdk,
                                                self._output_dir,
                                                self._startup_timeout_sec,
                                                self._destination_timeout_sec,
                                                os_version=os_version)
            # The xcresult only contains raw data in Xcode 11 or later.
            if xcode_info_util.GetXcodeVersionNumber() >= 1100:
                test_log_dir = '%s/Logs/Test' % self._output_dir
                xcresults = glob.glob('%s/*.xcresult' % test_log_dir)
                for xcresult in xcresults:
                    xcresult_util.ExposeDiagnosticsRef(xcresult, test_log_dir)
                    shutil.rmtree(xcresult)
            return exit_code
        elif self._logic_test_bundle:
            return logic_test_util.RunLogicTestOnSim(device_id,
                                                     self._logic_test_bundle,
                                                     self._logic_test_env_vars,
                                                     self._logic_test_args,
                                                     self._logic_tests_to_run,
                                                     os_version=os_version)
        else:
            raise ios_errors.XcodebuildTestError('Unexpected runtime error.')
    def SetLaunchOptions(self, launch_options):
        """Set the launch options to xctest session.

    Args:
      launch_options: dict, the signing app options. See
          ios_constants.LAUNCH_OPTIONS_JSON_HELP for details.
    """
        if not self._prepared:
            raise ios_errors.XcodebuildTestError(
                'The session has not been prepared. Please call '
                'XctestSession.Prepare first.')
        if not launch_options:
            return
        self._startup_timeout_sec = launch_options.get('startup_timeout_sec')
        self._destination_timeout_sec = launch_options.get(
            'destination_timeout_sec')
        if self._xctestrun_obj:
            self._xctestrun_obj.SetTestEnvVars(launch_options.get('env_vars'))
            self._xctestrun_obj.SetTestArgs(launch_options.get('args'))
            self._xctestrun_obj.SetTestsToRun(
                launch_options.get('tests_to_run'))
            self._xctestrun_obj.SetSkipTests(launch_options.get('skip_tests'))
            self._xctestrun_obj.SetAppUnderTestEnvVars(
                launch_options.get('app_under_test_env_vars'))
            self._xctestrun_obj.SetAppUnderTestArgs(
                launch_options.get('app_under_test_args'))

            if launch_options.get('uitest_auto_screenshots'):
                self._disable_uitest_auto_screenshots = False
                # By default, this SystemAttachmentLifetime field is in the generated
                # xctestrun.plist.
                try:
                    self._xctestrun_obj.DeleteXctestrunField(
                        'SystemAttachmentLifetime')
                except ios_errors.PlistError:
                    pass
        elif self._dummy_project_obj:
            self._dummy_project_obj.SetEnvVars(launch_options.get('env_vars'))
            self._dummy_project_obj.SetArgs(launch_options.get('args'))
            self._dummy_project_obj.SetSkipTests(
                launch_options.get('skip_tests'))
        elif self._logic_test_bundle:
            self._logic_test_env_vars = launch_options.get('env_vars')
            self._logic_test_args = launch_options.get('args')
            self._logic_tests_to_run = launch_options.get('tests_to_run')