• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# Copyright 2018 The Chromium Authors
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5"""Runs chrome driver tests.
6
7This script attempts to emulate the contract of gtest-style tests
8invoked via recipes.
9
10If optional argument --isolated-script-test-output=[FILENAME] is passed
11to the script, json is written to that file in the format detailed in
12//docs/testing/json-test-results-format.md.
13
14If optional argument --isolated-script-test-filter=[TEST_NAMES] is passed to
15the script, it should be a  double-colon-separated ("::") list of test names,
16to run just that subset of tests. This list is forwarded to the chrome driver
17test runner.  """
18
19import json
20import sys
21
22import common
23
24
25class ChromeDriverAdapter(common.BaseIsolatedScriptArgsAdapter):
26
27  def generate_test_output_args(self, output):
28    return ['--isolated-script-test-output', output]
29
30  def generate_test_launcher_retry_limit_args(self, retry_limit):
31    if any('--retry-limit' in arg for arg in self.rest_args):
32      self.parser.error("can't have the test call filter with the "
33                        '--isolated-script-test-launcher-retry-limit argument '
34                        'to the wrapper script')
35    return ['--retry-limit=%d' % retry_limit]
36
37  def generate_test_repeat_args(self, repeat_count):
38    if any('--repeat' in arg for arg in self.rest_args):
39      self.parser.error(
40          "can't have the test call filter with the "
41          '--isolated-script-test-repeat argument to the wrapper script')
42    return ['--repeat=%d' % repeat_count]
43
44  def generate_test_filter_args(self, test_filter_str):
45    if any('--filter' in arg for arg in self.rest_args):
46      self.parser.error(
47          "can't have the test call filter with the "
48          '--isolated-script-test-filter argument to the wrapper script')
49
50    return ['--filter', test_filter_str.replace('::', ':')]
51
52
53def main():
54  adapter = ChromeDriverAdapter()
55  return adapter.run_test()
56
57
58# This is not really a "script test" so does not need to manually add
59# any additional compile targets.
60def main_compile_targets(args):
61  json.dump([], args.output)
62
63
64if __name__ == '__main__':
65  # Conform minimally to the protocol defined by ScriptTest.
66  if 'compile_targets' in sys.argv:
67    funcs = {
68        'run': None,
69        'compile_targets': main_compile_targets,
70    }
71    sys.exit(common.run_script(sys.argv[1:], funcs))
72  sys.exit(main())
73