Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / build / android / pylib / uiautomator / test_runner.py
1 # 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
7 from pylib import constants
8 from pylib import flag_changer
9 from pylib.instrumentation import test_options as instr_test_options
10 from pylib.instrumentation import test_runner as instr_test_runner
11
12
13 class TestRunner(instr_test_runner.TestRunner):
14   """Responsible for running a series of tests connected to a single device."""
15
16   def __init__(self, test_options, device, shard_index, test_pkg):
17     """Create a new TestRunner.
18
19     Args:
20       test_options: A UIAutomatorOptions object.
21       device: Attached android device.
22       shard_index: Shard index.
23       test_pkg: A TestPackage object.
24     """
25     # Create an InstrumentationOptions object to pass to the super class
26     instrumentation_options = instr_test_options.InstrumentationOptions(
27         test_options.tool,
28         test_options.cleanup_test_files,
29         test_options.push_deps,
30         test_options.annotations,
31         test_options.exclude_annotations,
32         test_options.test_filter,
33         test_options.test_data,
34         test_options.save_perf_json,
35         test_options.screenshot_failures,
36         wait_for_debugger=False,
37         coverage_dir=None,
38         test_apk=None,
39         test_apk_path=None,
40         test_apk_jar_path=None)
41     super(TestRunner, self).__init__(instrumentation_options, device,
42                                      shard_index, test_pkg)
43
44     cmdline_file = constants.PACKAGE_INFO[test_options.package].cmdline_file
45     self.flags = None
46     if cmdline_file:
47       self.flags = flag_changer.FlagChanger(self.device, cmdline_file)
48     self._package = constants.PACKAGE_INFO[test_options.package].package
49     self._activity = constants.PACKAGE_INFO[test_options.package].activity
50
51   #override
52   def InstallTestPackage(self):
53     self.test_pkg.Install(self.device)
54
55   #override
56   def PushDataDeps(self):
57     pass
58
59   #override
60   def _RunTest(self, test, timeout):
61     self.device.old_interface.ClearApplicationState(self._package)
62     if self.flags:
63       if 'Feature:FirstRunExperience' in self.test_pkg.GetTestAnnotations(test):
64         self.flags.RemoveFlags(['--disable-fre'])
65       else:
66         self.flags.AddFlags(['--disable-fre'])
67     self.device.old_interface.StartActivity(self._package,
68                            self._activity,
69                            wait_for_completion=True,
70                            action='android.intent.action.MAIN',
71                            force_stop=True)
72     return self.device.old_interface.RunUIAutomatorTest(
73         test, self.test_pkg.GetPackageName(), timeout)