OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import argparse | 5 import argparse |
6 import json | 6 import json |
7 import os | 7 import os |
8 import shlex | 8 import shlex |
9 import sys | 9 import sys |
10 import time | 10 import time |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 def __enter__(self): | 71 def __enter__(self): |
72 return self | 72 return self |
73 | 73 |
74 def __exit__(self, exc_type, exc_value, tb): | 74 def __exit__(self, exc_type, exc_value, tb): |
75 if self._driver: | 75 if self._driver: |
76 self._StopDriver() | 76 self._StopDriver() |
77 | 77 |
78 def _OverrideChromeArgs(self): | 78 def _OverrideChromeArgs(self): |
79 """ | 79 """ |
80 Overrides any given flags in the code with those given on the command line. | 80 Overrides any given arguments in the code with those given on the command |
| 81 line. Arguments that need to be overridden may contain different values for |
| 82 a flag given in the code. In that case, check by the flag whether to |
| 83 override the argument. |
81 """ | 84 """ |
| 85 def GetDictKey(argument): |
| 86 return argument.split('=', 1)[0] |
82 if self._flags.browser_args and len(self._flags.browser_args) > 0: | 87 if self._flags.browser_args and len(self._flags.browser_args) > 0: |
83 for arg in shlex.split(self._flags.browser_args): | 88 # Build a dict of flags mapped to the whole argument. |
84 self._chrome_args.add(arg) | 89 original_args = {} |
| 90 for arg in self._chrome_args: |
| 91 original_args[GetDictKey(arg)] = arg |
| 92 # Override by flag. |
| 93 for override_arg in shlex.split(self._flags.browser_args[0]): |
| 94 arg_key = GetDictKey(override_arg) |
| 95 if arg_key in original_args: |
| 96 self._chrome_args.remove(original_args[arg_key]) |
| 97 self._chrome_args.add(override_arg) |
85 | 98 |
86 def _StartDriver(self): | 99 def _StartDriver(self): |
87 """ | 100 """ |
88 Parses the flags to pass to Chromium, then starts the ChromeDriver. | 101 Parses the flags to pass to Chromium, then starts the ChromeDriver. |
89 """ | 102 """ |
| 103 self._OverrideChromeArgs() |
90 options = Options() | 104 options = Options() |
91 for arg in self._chrome_args: | 105 for arg in self._chrome_args: |
92 options.add_argument(arg) | 106 options.add_argument(arg) |
93 capabilities = {'loggingPrefs': {'performance': 'INFO'}} | 107 capabilities = {'loggingPrefs': {'performance': 'INFO'}} |
94 if self._flags.chrome_exec: | 108 if self._flags.chrome_exec: |
95 capabilities['chrome.binary'] = self._flags.chrome_exec | 109 capabilities['chrome.binary'] = self._flags.chrome_exec |
96 driver = webdriver.Chrome(executable_path=self._flags.chrome_driver[0], | 110 driver = webdriver.Chrome(executable_path=self._flags.chrome_driver[0], |
97 chrome_options=options, desired_capabilities=capabilities) | 111 chrome_options=options, desired_capabilities=capabilities) |
98 driver.command_executor._commands.update({ | 112 driver.command_executor._commands.update({ |
99 'getAvailableLogTypes': ('GET', '/session/$sessionId/log/types'), | 113 'getAvailableLogTypes': ('GET', '/session/$sessionId/log/types'), |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 def Fail(self, msg): | 218 def Fail(self, msg): |
205 sys.stderr.write("**************************************\n") | 219 sys.stderr.write("**************************************\n") |
206 sys.stderr.write("**************************************\n") | 220 sys.stderr.write("**************************************\n") |
207 sys.stderr.write("** **\n") | 221 sys.stderr.write("** **\n") |
208 sys.stderr.write("** TEST FAILURE **\n") | 222 sys.stderr.write("** TEST FAILURE **\n") |
209 sys.stderr.write("** **\n") | 223 sys.stderr.write("** **\n") |
210 sys.stderr.write("**************************************\n") | 224 sys.stderr.write("**************************************\n") |
211 sys.stderr.write("**************************************\n") | 225 sys.stderr.write("**************************************\n") |
212 sys.stderr.write(msg, '\n') | 226 sys.stderr.write(msg, '\n') |
213 sys.exit(1) | 227 sys.exit(1) |
OLD | NEW |