OLD | NEW |
| (Empty) |
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 | |
3 # found in the LICENSE file. | |
4 | |
5 """Run specific test on specific environment.""" | |
6 | |
7 import logging | |
8 | |
9 from pylib.base import base_test_result | |
10 from pylib.remote.device import appurify_sanitized | |
11 from pylib.remote.device import remote_device_test_run | |
12 from pylib.remote.device import remote_device_helper | |
13 | |
14 | |
15 class RemoteDeviceUirobotTestRun(remote_device_test_run.RemoteDeviceTestRun): | |
16 """Run uirobot tests on a remote device.""" | |
17 | |
18 | |
19 def __init__(self, env, test_instance): | |
20 """Constructor. | |
21 | |
22 Args: | |
23 env: Environment the tests will run in. | |
24 test_instance: The test that will be run. | |
25 """ | |
26 super(RemoteDeviceUirobotTestRun, self).__init__(env, test_instance) | |
27 | |
28 #override | |
29 def TestPackage(self): | |
30 return self._test_instance.package_name | |
31 | |
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. | |
59 #override | |
60 def _UploadTestToDevice(self, test_type, test_path, app_id=None): | |
61 if test_path: | |
62 logging.info("Ignoring test path.") | |
63 data = { | |
64 'access_token':self._env.token, | |
65 'test_type':test_type, | |
66 'app_id':app_id, | |
67 } | |
68 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, | |
69 logging.WARNING): | |
70 test_upload_res = appurify_sanitized.utils.post('tests/upload', | |
71 data, None) | |
72 remote_device_helper.TestHttpResponse( | |
73 test_upload_res, 'Unable to get UiRobot test id.') | |
74 return test_upload_res.json()['response']['test_id'] | |
75 | |
76 #override | |
77 def _ParseTestResults(self): | |
78 logging.info('Parsing results from remote service.') | |
79 results = base_test_result.TestRunResults() | |
80 if self._results['results']['pass']: | |
81 result_type = base_test_result.ResultType.PASS | |
82 else: | |
83 result_type = base_test_result.ResultType.FAIL | |
84 results.AddResult(base_test_result.BaseTestResult('uirobot', result_type)) | |
85 return results | |
OLD | NEW |