| 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 | |
| 19 def __init__(self, env, test_instance): | 18 def __init__(self, env, test_instance): |
| 20 """Constructor. | 19 """Constructor. |
| 21 | 20 |
| 22 Args: | 21 Args: |
| 23 env: Environment the tests will run in. | 22 env: Environment the tests will run in. |
| 24 test_instance: The test that will be run. | 23 test_instance: The test that will be run. |
| 25 """ | 24 """ |
| 26 super(RemoteDeviceUirobotTestRun, self).__init__(env, test_instance) | 25 super(RemoteDeviceUirobotTestRun, self).__init__(env, test_instance) |
| 27 | 26 |
| 28 #override | 27 #override |
| 28 def _GetAdditionalApks(self): |
| 29 return None |
| 30 |
| 31 #override |
| 32 def _GetAppPath(self): |
| 33 return self._test_instance.app_under_test |
| 34 |
| 35 #override |
| 36 def _GetTestFramework(self): |
| 37 if self._env.test_framework: |
| 38 return self._env.test_framework |
| 39 elif self._env.device_type == 'Android': |
| 40 return 'android_robot' |
| 41 elif self._env.device_type == 'iOS': |
| 42 return 'ios_robot' |
| 43 else: |
| 44 raise remote_device_helper.RemoteDeviceError( |
| 45 'Unknown device type: %s' % self._env.device_type) |
| 46 |
| 47 #override |
| 48 def _GetTestPath(self): |
| 49 return None |
| 50 |
| 51 #override |
| 52 def _GetTestRunnerName(self): |
| 53 return None |
| 54 |
| 55 #override |
| 56 def _GetFrameworkConfigs(self): |
| 57 return {'duration': self._test_instance.minutes} |
| 58 |
| 59 #override |
| 60 def _GetShardEnvironmentVars(self, num_shards): |
| 61 return None |
| 62 |
| 63 #override |
| 64 def _ShouldShard(self): |
| 65 return False |
| 66 |
| 67 #override |
| 29 def TestPackage(self): | 68 def TestPackage(self): |
| 30 return self._test_instance.package_name | 69 return self._test_instance.package_name |
| 31 | 70 |
| 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. | 71 # TODO(rnephew): Switch to base class implementation when supported. |
| 59 #override | 72 # override |
| 60 def _UploadTestToDevice(self, test_type, test_path, app_id=None): | 73 def _UploadTestToDevice(self): |
| 61 if test_path: | |
| 62 logging.info("Ignoring test path.") | |
| 63 data = { | 74 data = { |
| 64 'access_token':self._env.token, | 75 'access_token': self._env.token, |
| 65 'test_type':test_type, | 76 'test_type': self._GetTestFramework(), |
| 66 'app_id':app_id, | 77 'app_id': self._app_id, |
| 67 } | 78 } |
| 68 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, | 79 with appurify_sanitized.SanitizeLogging( |
| 69 logging.WARNING): | 80 verbose_count=self._env.verbose_count, |
| 70 test_upload_res = appurify_sanitized.utils.post('tests/upload', | 81 level=logging.WARNING): |
| 71 data, None) | 82 test_upload_response = appurify_sanitized.utils.post( |
| 83 resource='tests/upload', |
| 84 data=data, |
| 85 files=None) |
| 72 remote_device_helper.TestHttpResponse( | 86 remote_device_helper.TestHttpResponse( |
| 73 test_upload_res, 'Unable to get UiRobot test id.') | 87 response=test_upload_response, |
| 74 return test_upload_res.json()['response']['test_id'] | 88 error_msg='Unable to get UiRobot test id.') |
| 89 return test_upload_response.json()['response']['test_id'] |
| 75 | 90 |
| 76 #override | 91 #override |
| 77 def _ParseTestResults(self): | 92 def _ParseTestResults(self, test_output, results_zip): |
| 78 logging.info('Parsing results from remote service.') | 93 logging.info('Parsing results from remote service.') |
| 79 results = base_test_result.TestRunResults() | 94 results = base_test_result.TestRunResults() |
| 80 if self._results['results']['pass']: | 95 if test_output['results']['pass']: |
| 81 result_type = base_test_result.ResultType.PASS | 96 result_type = base_test_result.ResultType.PASS |
| 82 else: | 97 else: |
| 83 result_type = base_test_result.ResultType.FAIL | 98 result_type = base_test_result.ResultType.FAIL |
| 84 results.AddResult(base_test_result.BaseTestResult('uirobot', result_type)) | 99 results.AddResult(base_test_result.BaseTestResult('uirobot', result_type)) |
| 100 self._DetectPlatformErrors(results, test_output, results_zip) |
| 85 return results | 101 return results |
| OLD | NEW |