| OLD | NEW | 
|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be | 
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. | 
| 4 | 4 | 
| 5 """Run specific test on specific environment.""" | 5 """Run specific test on specific environment.""" | 
| 6 | 6 | 
| 7 import logging | 7 import logging | 
| 8 | 8 | 
| 9 from pylib.base import base_test_result | 9 from pylib.base import base_test_result | 
| 10 from pylib.remote.device import appurify_sanitized | 10 from pylib.remote.device import appurify_sanitized | 
| 11 from pylib.remote.device import remote_device_test_run | 11 from pylib.remote.device import remote_device_test_run | 
| 12 from pylib.remote.device import remote_device_helper | 12 from pylib.remote.device import remote_device_helper | 
| 13 | 13 | 
| 14 | 14 | 
| 15 class RemoteDeviceUirobotTestRun(remote_device_test_run.RemoteDeviceTestRun): | 15 class RemoteDeviceUirobotTestRun(remote_device_test_run.RemoteDeviceTestRun): | 
| 16   """Run uirobot tests on a remote device.""" | 16   """Run uirobot tests on a remote device.""" | 
| 17 | 17 | 
| 18 | 18 | 
| 19   def __init__(self, env, test_instance): | 19   def __init__(self, env, test_instance): | 
| 20     """Constructor. | 20     """Constructor. | 
| 21 | 21 | 
| 22     Args: | 22     Args: | 
| 23       env: Environment the tests will run in. | 23       env: Environment the tests will run in. | 
| 24       test_instance: The test that will be run. | 24       test_instance: The test that will be run. | 
| 25     """ | 25     """ | 
| 26     super(RemoteDeviceUirobotTestRun, self).__init__(env, test_instance) | 26     super(RemoteDeviceUirobotTestRun, self).__init__(env, test_instance) | 
| 27 | 27 | 
| 28   #override | 28   #override | 
|  | 29   def _GetAppPath(self): | 
|  | 30     return self._test_instance.app_under_test | 
|  | 31 | 
|  | 32   #override | 
|  | 33   def _GetTestFramework(self): | 
|  | 34     if self._env.test_framework: | 
|  | 35       return self._env.test_framework | 
|  | 36     elif self._env.device_type == 'Android': | 
|  | 37       return 'android_robot' | 
|  | 38     elif self._env.device_type == 'iOS': | 
|  | 39       return 'ios_robot' | 
|  | 40     else: | 
|  | 41       raise remote_device_helper.RemoteDeviceError( | 
|  | 42           'Unknown device type: %s' % self._env.device_type) | 
|  | 43 | 
|  | 44   #override | 
|  | 45   def _SetupTestShards(self, num_shards): | 
|  | 46     test_ids = [] | 
|  | 47     framework_configs = {'duration': self._test_instance.minutes} | 
|  | 48 | 
|  | 49     test_id = self._UploadTestToDevice(None) | 
|  | 50     self._UploadTestConfigToDevice( | 
|  | 51         test_id, framework_configs, self._appurify_configs) | 
|  | 52     test_ids.append(test_id) | 
|  | 53 | 
|  | 54     return test_ids | 
|  | 55 | 
|  | 56   #override | 
| 29   def TestPackage(self): | 57   def TestPackage(self): | 
| 30     return self._test_instance.package_name | 58     return self._test_instance.package_name | 
| 31 | 59 | 
| 32   #override |  | 
| 33   def _TriggerSetUp(self): |  | 
| 34     """Set up the triggering of a test run.""" |  | 
| 35     logging.info('Triggering test run.') |  | 
| 36 |  | 
| 37     if self._env.device_type == 'Android': |  | 
| 38       default_runner_type = 'android_robot' |  | 
| 39     elif self._env.device_type == 'iOS': |  | 
| 40       default_runner_type = 'ios_robot' |  | 
| 41     else: |  | 
| 42       raise remote_device_helper.RemoteDeviceError( |  | 
| 43           'Unknown device type: %s' % self._env.device_type) |  | 
| 44 |  | 
| 45     self._app_id = self._UploadAppToDevice(self._test_instance.app_under_test) |  | 
| 46     if not self._env.runner_type: |  | 
| 47       runner_type = default_runner_type |  | 
| 48       logging.info('Using default runner type: %s', default_runner_type) |  | 
| 49     else: |  | 
| 50       runner_type = self._env.runner_type |  | 
| 51 |  | 
| 52     self._test_id = self._UploadTestToDevice( |  | 
| 53         'android_robot', None, app_id=self._app_id) |  | 
| 54     config_body = {'duration': self._test_instance.minutes} |  | 
| 55     self._SetTestConfig(runner_type, config_body) |  | 
| 56 |  | 
| 57 |  | 
| 58   # TODO(rnephew): Switch to base class implementation when supported. | 60   # TODO(rnephew): Switch to base class implementation when supported. | 
| 59   #override | 61   #override | 
| 60   def _UploadTestToDevice(self, test_type, test_path, app_id=None): | 62   def _UploadTestToDevice(self, test_path): | 
| 61     if test_path: |  | 
| 62       logging.info("Ignoring test path.") |  | 
| 63     data = { | 63     data = { | 
| 64         'access_token':self._env.token, | 64         'access_token': self._env.token, | 
| 65         'test_type':test_type, | 65         'test_type': self._GetTestFramework(), | 
| 66         'app_id':app_id, | 66         'app_id': self._app_id, | 
| 67     } | 67     } | 
| 68     with appurify_sanitized.SanitizeLogging(self._env.verbose_count, | 68     with appurify_sanitized.SanitizeLogging(self._env.verbose_count, | 
| 69                                             logging.WARNING): | 69                                             logging.WARNING): | 
| 70       test_upload_res = appurify_sanitized.utils.post('tests/upload', | 70       test_upload_response = appurify_sanitized.utils.post( | 
| 71                                                       data, None) | 71           resource='tests/upload', data=data, files=None) | 
| 72     remote_device_helper.TestHttpResponse( | 72     remote_device_helper.TestHttpResponse(test_upload_response, | 
| 73         test_upload_res, 'Unable to get UiRobot test id.') | 73                                           'Unable to get UiRobot test id.') | 
| 74     return test_upload_res.json()['response']['test_id'] | 74     return test_upload_response.json()['response']['test_id'] | 
| 75 | 75 | 
| 76   #override | 76   #override | 
| 77   def _ParseTestResults(self): | 77   def _ParseTestResults(self, test_output, results_zip): | 
| 78     logging.info('Parsing results from remote service.') | 78     logging.info('Parsing results from remote service.') | 
| 79     results = base_test_result.TestRunResults() | 79     results = base_test_result.TestRunResults() | 
| 80     if self._results['results']['pass']: | 80     if test_output['results']['pass']: | 
| 81       result_type = base_test_result.ResultType.PASS | 81       result_type = base_test_result.ResultType.PASS | 
| 82     else: | 82     else: | 
| 83       result_type = base_test_result.ResultType.FAIL | 83       result_type = base_test_result.ResultType.FAIL | 
| 84     results.AddResult(base_test_result.BaseTestResult('uirobot', result_type)) | 84     results.AddResult(base_test_result.BaseTestResult('uirobot', result_type)) | 
|  | 85     remote_device_test_run.DetectPlatformErrors( | 
|  | 86         results, test_output, results_zip) | 
| 85     return results | 87     return results | 
| OLD | NEW | 
|---|