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.
5 """Run specific test on specific environment."""
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
15 class RemoteDeviceUirobotTestRun(remote_device_test_run
.RemoteDeviceTestRun
):
16 """Run uirobot tests on a remote device."""
19 def __init__(self
, env
, test_instance
):
23 env: Environment the tests will run in.
24 test_instance: The test that will be run.
26 super(RemoteDeviceUirobotTestRun
, self
).__init
__(env
, test_instance
)
29 def TestPackage(self
):
30 return self
._test
_instance
.package_name
33 def _TriggerSetUp(self
):
34 """Set up the triggering of a test run."""
35 logging
.info('Triggering test run.')
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'
42 raise remote_device_helper
.RemoteDeviceError(
43 'Unknown device type: %s' % self
._env
.device_type
)
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
)
50 runner_type
= self
._env
.runner_type
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
)
58 # TODO(rnephew): Switch to base class implementation when supported.
60 def _UploadTestToDevice(self
, test_type
, test_path
, app_id
=None):
62 logging
.info("Ignoring test path.")
64 'access_token':self
._env
.token
,
65 'test_type':test_type
,
68 with appurify_sanitized
.SanitizeLogging(self
._env
.verbose_count
,
70 test_upload_res
= appurify_sanitized
.utils
.post('tests/upload',
72 remote_device_helper
.TestHttpResponse(
73 test_upload_res
, 'Unable to get UiRobot test id.')
74 return test_upload_res
.json()['response']['test_id']
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
83 result_type
= base_test_result
.ResultType
.FAIL
84 results
.AddResult(base_test_result
.BaseTestResult('uirobot', result_type
))