blob: 58cdd45dd0a0c8d173ced9380a08bebc33324f64 [file] [log] [blame]
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +01001# Copyright (c) 2013 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"""Class for running uiautomator tests on a single device."""
6
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +01007from pylib.instrumentation import test_options as instr_test_options
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +01008from pylib.instrumentation import test_runner as instr_test_runner
9
10
11class TestRunner(instr_test_runner.TestRunner):
12 """Responsible for running a series of tests connected to a single device."""
13
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +010014 def __init__(self, test_options, device, shard_index, test_pkg,
15 ports_to_forward):
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010016 """Create a new TestRunner.
17
18 Args:
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +010019 test_options: A UIAutomatorOptions object.
20 device: Attached android device.
21 shard_index: Shard index.
22 test_pkg: A TestPackage object.
23 ports_to_forward: A list of port numbers for which to set up forwarders.
24 Can be optionally requested by a test case.
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010025 """
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +010026 # Create an InstrumentationOptions object to pass to the super class
27 instrumentation_options = instr_test_options.InstrumentationOptions(
28 test_options.build_type,
29 test_options.tool,
30 test_options.cleanup_test_files,
31 test_options.push_deps,
32 test_options.annotations,
33 test_options.exclude_annotations,
34 test_options.test_filter,
35 test_options.test_data,
36 test_options.save_perf_json,
37 test_options.screenshot_failures,
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +010038 wait_for_debugger=False,
39 test_apk=None,
40 test_apk_path=None,
41 test_apk_jar_path=None)
42 super(TestRunner, self).__init__(instrumentation_options, device,
43 shard_index, test_pkg, ports_to_forward)
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010044
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +010045 self.package_name = test_options.package_name
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010046
47 #override
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010048 def InstallTestPackage(self):
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +010049 self.test_pkg.Install(self.adb)
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010050
51 #override
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010052 def PushDataDeps(self):
53 pass
54
55 #override
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010056 def _RunTest(self, test, timeout):
57 self.adb.ClearApplicationState(self.package_name)
58 if 'Feature:FirstRunExperience' in self.test_pkg.GetTestAnnotations(test):
59 self.flags.RemoveFlags(['--disable-fre'])
60 else:
61 self.flags.AddFlags(['--disable-fre'])
62 return self.adb.RunUIAutomatorTest(
63 test, self.test_pkg.GetPackageName(), timeout)