示例#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.')