def _UploadTestToDevice(self, test_type, test_path, app_id=None):
   if test_path:
     logging.info("Ignoring test path.")
   data = {
       'access_token':self._env.token,
       'test_type':test_type,
       'app_id':app_id,
   }
   with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
                                           logging.WARNING):
     test_upload_res = appurify_sanitized.utils.post('tests/upload',
                                                     data, None)
   remote_device_helper.TestHttpResponse(
       test_upload_res, 'Unable to get UiRobot test id.')
   return test_upload_res.json()['response']['test_id']
예제 #2
0
    def _GetTestStatus(self, test_run_id):
        """Checks the state of the test, and sets self._results

    Args:
      test_run_id: Id of test on on remote service.
    """

        with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
                                                logging.WARNING):
            test_check_res = appurify_sanitized.api.tests_check_result(
                self._env.token, test_run_id)
        remote_device_helper.TestHttpResponse(test_check_res,
                                              'Unable to get test status.')
        self._results = test_check_res.json()['response']
        return self._results['status']
예제 #3
0
 def _SetTestConfig(self, runner_type, body):
   """Generates and uploads config file for test.
   Args:
     extras: Extra arguments to set in the config file.
   """
   with tempfile.TemporaryFile() as config:
     config_data = ['[appurify]', '[%s]' % runner_type]
     config_data.extend('%s=%s' % (k, v) for k, v in body.iteritems())
     config.write(''.join('%s\n' % l for l in config_data))
     config.flush()
     config.seek(0)
     config_response = appurify.api.config_upload(self._env.token,
                                                  config, self._test_id)
     remote_device_helper.TestHttpResponse(config_response,
                                           'Unable to upload test config.')
예제 #4
0
 def _UploadAppToDevice(self, app_path):
     """Upload app to device."""
     logging.info('Uploading %s to remote service as %s.', app_path,
                  self._test_instance.suite)
     with open(app_path, 'rb') as apk_src:
         with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
                                                 logging.WARNING):
             upload_results = appurify_sanitized.api.apps_upload(
                 self._env.token,
                 apk_src,
                 'raw',
                 name=self._test_instance.suite)
         remote_device_helper.TestHttpResponse(
             upload_results, 'Unable to upload %s.' % app_path)
         return upload_results.json()['response']['app_id']
예제 #5
0
  def _GetTestByName(self, test_name):
    """Gets test_id for specific test.

    Args:
      test_name: Test to find the ID of.
    """
    with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
                                            logging.WARNING):
      test_list_res = appurify_sanitized.api.tests_list(self._env.token)
    remote_device_helper.TestHttpResponse(test_list_res,
                                          'Unable to get tests list.')
    for test in test_list_res.json()['response']:
      if test['test_type'] == test_name:
        return test['test_id']
    raise remote_device_helper.RemoteDeviceError(
        'No test found with name %s' % (test_name))
예제 #6
0
    def RunTests(self):
        """Run the test."""
        if self._env.trigger:
            with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
                                                    logging.WARNING):
                test_start_res = appurify_sanitized.api.tests_run(
                    self._env.token, self._env.device_type_id, self._app_id,
                    self._test_id)
            remote_device_helper.TestHttpResponse(test_start_res,
                                                  'Unable to run test.')
            self._test_run_id = test_start_res.json(
            )['response']['test_run_id']
            logging.info('Test run id: %s' % self._test_run_id)

        if self._env.collect:
            current_status = ''
            timeout_counter = 0
            heartbeat_counter = 0
            while self._GetTestStatus(self._test_run_id) != self.COMPLETE:
                if self._results['detailed_status'] != current_status:
                    logging.info('Test status: %s',
                                 self._results['detailed_status'])
                    current_status = self._results['detailed_status']
                    timeout_counter = 0
                    heartbeat_counter = 0
                if heartbeat_counter > self.HEARTBEAT_INTERVAL:
                    logging.info('Test status: %s',
                                 self._results['detailed_status'])
                    heartbeat_counter = 0

                timeout = self._env.timeouts.get(current_status,
                                                 self._env.timeouts['unknown'])
                if timeout_counter > timeout:
                    raise remote_device_helper.RemoteDeviceError(
                        'Timeout while in %s state for %s seconds' %
                        (current_status, timeout),
                        is_infra_error=True)
                time.sleep(self.WAIT_TIME)
                timeout_counter += self.WAIT_TIME
                heartbeat_counter += self.WAIT_TIME
            self._DownloadTestResults(self._env.results_path)

            if self._results['results']['exception']:
                raise remote_device_helper.RemoteDeviceError(
                    self._results['results']['exception'], is_infra_error=True)

            return self._ParseTestResults()
예제 #7
0
 def _SetTestConfig(self, runner_type, body):
     """Generates and uploads config file for test.
 Args:
   extras: Extra arguments to set in the config file.
 """
     logging.info('Generating config file for test.')
     with tempfile.TemporaryFile() as config:
         config_data = [
             '[appurify]', 'pcap=0', 'profiler=0', 'videocapture=0',
             '[%s]' % runner_type
         ]
         config_data.extend('%s=%s' % (k, v) for k, v in body.iteritems())
         config.write(''.join('%s\n' % l for l in config_data))
         config.flush()
         config.seek(0)
         with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
                                                 logging.WARNING):
             config_response = appurify_sanitized.api.config_upload(
                 self._env.token, config, self._test_id)
         remote_device_helper.TestHttpResponse(
             config_response, 'Unable to upload test config.')
예제 #8
0
    def _SetTestConfig(self,
                       runner_type,
                       runner_configs,
                       network=appurify_constants.NETWORK.WIFI_1_BAR,
                       pcap=0,
                       profiler=0,
                       videocapture=0):
        """Generates and uploads config file for test.
    Args:
      runner_configs: Configs specific to the runner you are using.
      network: Config to specify the network environment the devices running
          the tests will be in.
      pcap: Option to set the recording the of network traffic from the device.
      profiler: Option to set the recording of CPU, memory, and network
          transfer usage in the tests.
      videocapture: Option to set video capture during the tests.

    """
        logging.info('Generating config file for test.')
        with tempfile.TemporaryFile() as config:
            config_data = [
                '[appurify]',
                'network=%s' % network,
                'pcap=%s' % pcap,
                'profiler=%s' % profiler,
                'videocapture=%s' % videocapture,
                '[%s]' % runner_type
            ]
            config_data.extend('%s=%s' % (k, v)
                               for k, v in runner_configs.iteritems())
            config.write(''.join('%s\n' % l for l in config_data))
            config.flush()
            config.seek(0)
            with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
                                                    logging.WARNING):
                config_response = appurify_sanitized.api.config_upload(
                    self._env.token, config, self._test_id)
            remote_device_helper.TestHttpResponse(
                config_response, 'Unable to upload test config.')
예제 #9
0
  def RunTests(self):
    """Run the test."""
    if self._env.trigger:
      test_start_res = appurify.api.tests_run(
          self._env.token, self._env.device, self._app_id, self._test_id)
      remote_device_helper.TestHttpResponse(
        test_start_res, 'Unable to run test.')
      test_run_id = test_start_res.json()['response']['test_run_id']
      if not self._env.collect:
        assert isinstance(self._env.trigger, basestring), (
                          'File for storing test_run_id must be a string.')
        with open(self._env.trigger, 'w') as test_run_id_file:
          test_run_id_file.write(test_run_id)

    if self._env.collect:
      if not self._env.trigger:
        assert isinstance(self._env.trigger, basestring), (
                          'File for storing test_run_id must be a string.')
        with open(self._env.collect, 'r') as test_run_id_file:
          test_run_id = test_run_id_file.read()
      while self._GetTestStatus(test_run_id) != self.COMPLETE:
        time.sleep(self.WAIT_TIME)
      self._DownloadTestResults(self._env.results_path)
      return self._ParseTestResults()