def main(): options, args = _GetCommandLineOptions() server = StartChromeDriverServer(args[0], options) input_log_path = util.GetAbsolutePathOfUserPath(args[1]) chrome_binary = (util.GetAbsolutePathOfUserPath(options.chrome) if options.chrome else None) with open(input_log_path) as logfile: Replayer(logfile, server, chrome_binary, options.base_url).Run() server.Kill()
def StartChromeDriverServer(chromedriver_binary, options): chromedriver = util.GetAbsolutePathOfUserPath(chromedriver_binary) if (not os.path.exists(chromedriver) and util.GetPlatformName() == "win" and not chromedriver.lower().endswith(".exe")): chromedriver = chromedriver + ".exe" if options.output_log_path: options.output_log_path = util.GetAbsolutePathOfUserPath( options.output_log_path) chromedriver_server = server.Server(chromedriver_binary, log_path=options.output_log_path) return chromedriver_server
def runTest(self, test_name): """Runs the test. Compares output from Chrome to the output in the log file. Args: test_name: name of the test to run from run_py_tests.py. """ log_file = os.path.join(ChromeDriverClientReplayTest.log_dir, test_name + ".log") GenerateTestLog(test_name, _CHROMEDRIVER, _CHROME, log_file) with open(log_file) as lf: replay_path = log_file if _OPTIONS.devtools_replay else "" server = client_replay.StartChromeDriverServer( _CHROMEDRIVER, _OPTIONS.output_log_path, replay_path) chrome_binary = (util.GetAbsolutePathOfUserPath(_CHROME) if _CHROME else None) replayer = client_replay.Replayer(lf, server, chrome_binary, self.server_url) real_response = None while True: command = replayer.command_sequence.NextCommand(real_response) if not command: break logged_response = replayer.command_sequence._last_response real_response = replayer.executor.Execute( client_replay._COMMANDS[command.name], command.GetPayloadPrimitive()) self.CheckResponsesMatch(real_response["value"], logged_response.GetPayloadPrimitive()) server.Kill()
def main(): usage = "usage: %prog <chromedriver binary> [options]" parser = optparse.OptionParser(usage=usage) parser.add_option("", "--output-log-path", help="Output verbose server logs to this file") parser.add_option("", "--chrome", help="Path to the desired Chrome binary.") parser.add_option( "", "--filter", type="string", default="*", help= "Filter for specifying what tests to run, \"*\" will run all. E.g., " "*testRunMethod") global _OPTIONS, _CHROMEDRIVER _OPTIONS, args = parser.parse_args() _CHROMEDRIVER = util.GetAbsolutePathOfUserPath(args[0]) if not os.path.exists(_CHROMEDRIVER): parser.error("Path given by --chromedriver is invalid.\n" 'Please run "%s --help" for help' % __file__) if _OPTIONS.chrome and not os.path.exists(_OPTIONS.chrome): parser.error("Path given by --chrome is invalid.\n" 'Please run "%s --help" for help' % __file__) all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule( sys.modules[__name__]) tests = unittest_util.FilterTestSuite(all_tests_suite, _OPTIONS.filter) result = unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run(tests) sys.exit(len(result.failures) + len(result.errors))
def runTest(self, log_file_relative_path): """Runs the test. Args: log_file_relative_path: relative path (from this the directory this file is in) to the log file for this test as a string. """ log_file = os.path.join(_THIS_DIR, log_file_relative_path) with open(log_file) as lf: server = client_replay.StartChromeDriverServer( _CHROMEDRIVER, _OPTIONS) chrome_binary = (util.GetAbsolutePathOfUserPath(_OPTIONS.chrome) if _OPTIONS.chrome else None) replayer = client_replay.Replayer(lf, server, chrome_binary, self.server_url) real_response = None while True: command = replayer.command_sequence.NextCommand(real_response) logged_response = replayer.command_sequence._last_response if not command: break real_response = replayer.executor.Execute( client_replay._COMMANDS[command.name], command.GetPayloadPrimitive()) self.CheckResponsesMatch(real_response["value"], logged_response.GetPayloadPrimitive()) server.Kill()
def StartChromeDriverServer(chromedriver_binary, output_log_path, devtools_replay_path="", replayable=False): chromedriver = util.GetAbsolutePathOfUserPath(chromedriver_binary) if (not os.path.exists(chromedriver) and util.GetPlatformName() == "win" and not chromedriver.lower().endswith(".exe")): chromedriver = chromedriver + ".exe" if output_log_path: output_log_path = util.GetAbsolutePathOfUserPath(output_log_path) chromedriver_server = server.Server( chromedriver_binary, log_path=output_log_path, devtools_replay_path=devtools_replay_path, replayable=replayable) return chromedriver_server
def main(): usage = "usage: %prog <chromedriver binary> <chrome binary> [options]" parser = optparse.OptionParser(usage=usage) parser.add_option("", "--output-log-path", help="Output verbose server logs to this file") parser.add_option("", "--chrome-version", default="HEAD", help="Version of Chrome. Default is 'HEAD'.") parser.add_option( "", "--filter", type="string", default="*", help="Filter for specifying what tests to run, \"*\" will run all," "including tests excluded by default. E.g., *testRunMethod") parser.add_option("", "--devtools-replay", help="Replay DevTools instead of using\n" "real Chrome.") # Need global to access these from the test runner. # pylint: disable=global-variable-undefined global _OPTIONS, _CHROMEDRIVER, _CHROME # pylint: enable=global-variable-undefined _OPTIONS, args = parser.parse_args() _CHROMEDRIVER = util.GetAbsolutePathOfUserPath(args[0]) _CHROME = util.GetAbsolutePathOfUserPath(args[1]) if not os.path.exists(_CHROMEDRIVER): parser.error("Path given for chromedriver is invalid.\n" 'Please run "%s --help" for help' % __file__) if not os.path.exists(_CHROME): parser.error("Path given for chrome is invalid.\n" 'Please run "%s --help" for help' % __file__) all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule( sys.modules[__name__]) test_filter = (GetNegativeFilter(_OPTIONS.chrome_version) if not _OPTIONS.filter else _OPTIONS.filter) tests = unittest_util.FilterTestSuite(all_tests_suite, test_filter) result = unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run(tests) sys.exit(len(result.failures) + len(result.errors))
def testRunMethod(self): """Check the Replayer.run method, which the other tests bypass.""" log_path = os.path.join(_THIS_DIR, "test_data/testGetTitle.log") with open(log_path) as lf: server = client_replay.StartChromeDriverServer( _CHROMEDRIVER, _OPTIONS) chrome_binary = (util.GetAbsolutePathOfUserPath(_OPTIONS.chrome) if _OPTIONS.chrome else None) client_replay.Replayer(lf, server, chrome_binary, self.server_url).Run() server.Kill()
parser.add_option( '', '--chrome', help='Path to a build of the chrome binary') parser.add_option( '', '--chrome-version', default='HEAD', help='Version of chrome. Default is \'HEAD\'.') parser.add_option( '', '--filter', type='string', default='*', help=('Filter for specifying what tests to run, "*" will run all. E.g., ' '*testStartStop')) parser.add_option( '', '--android-package', help=('Android package key. Possible values: ' + str(_ANDROID_NEGATIVE_FILTER.keys()))) options, args = parser.parse_args() options.chromedriver = util.GetAbsolutePathOfUserPath(options.chromedriver) if not options.chromedriver or not os.path.exists(options.chromedriver): parser.error('chromedriver is required or the given path is invalid.' + 'Please run "%s --help" for help' % __file__) global _CHROMEDRIVER_BINARY _CHROMEDRIVER_BINARY = options.chromedriver if (options.android_package and options.android_package not in _ANDROID_NEGATIVE_FILTER): parser.error('Invalid --android-package') chromedriver_server = server.Server(_CHROMEDRIVER_BINARY, options.log_path) global _CHROMEDRIVER_SERVER_URL _CHROMEDRIVER_SERVER_URL = chromedriver_server.GetUrl()
log_level = logging.DEBUG if options.verbose else logging.INFO configure_logging(logging_level=log_level, include_time=True) host = Host() port = host.port_factory.get() path_finder = PathFinder(host.filesystem) # Starts WPT Serve to serve the WPT WebDriver test content. port.start_wptserve() # WebDriverExpectations stores skipped and failed WebDriver tests. expectations = parse_webdriver_expectations(host, port) skipped_tests = preprocess_skipped_tests(test_results, expectations, path_finder) options.chromedriver = util.GetAbsolutePathOfUserPath(options.chromedriver) if (not os.path.exists(options.chromedriver) and util.GetPlatformName() == 'win' and not options.chromedriver.lower().endswith('.exe')): options.chromedriver = options.chromedriver + '.exe' if not os.path.exists(options.chromedriver): parser.error('Path given by --chromedriver is invalid.\n' + 'Please run "%s --help" for help' % __file__) # Due to occasional timeout in starting ChromeDriver, retry once when needed. try: chromedriver_server = server.Server(options.chromedriver, options.log_path) except RuntimeError as e: _log.warn('Error starting ChromeDriver, retrying...')
def main(): parser = optparse.OptionParser() parser.add_option('', '--verbose', action='store_true', default=False, help='Whether output should be verbose') parser.add_option('', '--debug', action='store_true', default=False, help='Whether to wait to be attached by a debugger') parser.add_option( '', '--chromedriver', type='string', default=None, help='Path to a build of the chromedriver library(REQUIRED!)') parser.add_option('', '--chrome', type='string', default=None, help='Path to a build of the chrome binary') parser.add_option('', '--log-path', help='Output verbose server logs to this file') parser.add_option('', '--android-package', help='Android package key') parser.add_option( '', '--filter', type='string', default=None, help='Filter for specifying what tests to run, "*" will run all. E.g., ' '*testShouldReturnTitleOfPageIfSet') parser.add_option('', '--also-run-disabled-tests', action='store_true', default=False, help='Include disabled tests while running the tests') parser.add_option('', '--isolate-tests', action='store_true', default=False, help='Relaunch the jar test harness after each test') options, _ = parser.parse_args() options.chromedriver = util.GetAbsolutePathOfUserPath(options.chromedriver) if options.chromedriver is None or not os.path.exists( options.chromedriver): parser.error('chromedriver is required or the given path is invalid.' + 'Please run "%s --help" for help' % __file__) if options.android_package: if options.android_package not in constants.PACKAGE_INFO: parser.error('Invalid --android-package') environment = test_environment.AndroidTestEnvironment( options.android_package) else: environment = test_environment.DesktopTestEnvironment() try: environment.GlobalSetUp() # Run passed tests when filter is not provided. if options.isolate_tests: test_filters = environment.GetPassedJavaTests() else: if options.filter: test_filter = options.filter else: test_filter = '*' if not options.also_run_disabled_tests: if '-' in test_filter: test_filter += ':' else: test_filter += '-' test_filter += ':'.join( environment.GetDisabledJavaTestMatchers()) test_filters = [test_filter] ready_to_run_tests = ':'.join( environment.GetReadyToRunJavaTestMatchers()) java_tests_src_dir = os.path.join(chrome_paths.GetSrc(), 'chrome', 'test', 'chromedriver', 'third_party', 'java_tests') if (not os.path.exists(java_tests_src_dir) or not os.listdir(java_tests_src_dir)): java_tests_url = ('https://chromium.googlesource.com/chromium/deps' '/webdriver') print( '"%s" is empty or it doesn\'t exist. ' % java_tests_src_dir + 'Need to map ' + java_tests_url + ' to ' 'chrome/test/chromedriver/third_party/java_tests in .gclient.\n' 'Alternatively, do:\n' ' $ cd chrome/test/chromedriver/third_party\n' ' $ git clone %s java_tests' % java_tests_url) return 1 results = [] for filter in test_filters: results += _Run(java_tests_src_dir=java_tests_src_dir, test_filter=filter, ready_to_run_tests=ready_to_run_tests, chromedriver_path=options.chromedriver, chrome_path=util.GetAbsolutePathOfUserPath( options.chrome), log_path=options.log_path, android_package_key=options.android_package, verbose=options.verbose, debug=options.debug) return PrintTestResults(results) finally: environment.GlobalTearDown() if (os.path.exists(os.path.join(java_tests_src_dir, "build.xml"))): os.remove(os.path.join(java_tests_src_dir, "build.xml")) if (os.path.exists(os.path.join(java_tests_src_dir, "results.xml"))): os.remove(os.path.join(java_tests_src_dir, "results.xml")) if (os.path.exists( os.path.join(java_tests_src_dir, "chrome-wrapper-no-sandbox"))): os.remove( os.path.join(java_tests_src_dir, "chrome-wrapper-no-sandbox")) if (os.path.exists(os.path.join(java_tests_src_dir, "chrome-wrapper"))): os.remove(os.path.join(java_tests_src_dir, "chrome-wrapper"))