run_chromedriver_tests.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env python
  2. # Copyright 2018 The Chromium Authors. All rights reserved.
  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. This script attempts to emulate the contract of gtest-style tests
  7. invoked via recipes.
  8. If optional argument --isolated-script-test-output=[FILENAME] is passed
  9. to the script, json is written to that file in the format detailed in
  10. //docs/testing/json-test-results-format.md.
  11. If optional argument --isolated-script-test-filter=[TEST_NAMES] is passed to
  12. the script, it should be a double-colon-separated ("::") list of test names,
  13. to run just that subset of tests. This list is forwarded to the chrome driver
  14. test runner. """
  15. import argparse
  16. import json
  17. import os
  18. import shutil
  19. import sys
  20. import tempfile
  21. import traceback
  22. # Add src/testing/ into sys.path for importing common without pylint errors.
  23. sys.path.append(
  24. os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
  25. from scripts import common
  26. class ChromeDriverAdapter(common.BaseIsolatedScriptArgsAdapter):
  27. def generate_test_output_args(self, output):
  28. return ['--isolated-script-test-output', output]
  29. def generate_test_filter_args(self, test_filter_str):
  30. if any('--filter' in arg for arg in self.rest_args):
  31. self.parser.error(
  32. 'can\'t have the test call filter with the'
  33. '--isolated-script-test-filter argument to the wrapper script')
  34. return ['--filter', test_filter_str.replace('::', ':')]
  35. def main():
  36. adapter = ChromeDriverAdapter()
  37. return adapter.run_test()
  38. # This is not really a "script test" so does not need to manually add
  39. # any additional compile targets.
  40. def main_compile_targets(args):
  41. json.dump([], args.output)
  42. if __name__ == '__main__':
  43. # Conform minimally to the protocol defined by ScriptTest.
  44. if 'compile_targets' in sys.argv:
  45. funcs = {
  46. 'run': None,
  47. 'compile_targets': main_compile_targets,
  48. }
  49. sys.exit(common.run_script(sys.argv[1:], funcs))
  50. sys.exit(main())