Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 3 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 4 # for details. All rights reserved. Use of this source code is governed by a | 4 # for details. All rights reserved. Use of this source code is governed by a |
| 5 # BSD-style license that can be found in the LICENSE file. | 5 # BSD-style license that can be found in the LICENSE file. |
| 6 # | 6 # |
| 7 | 7 |
| 8 """Script to actually open a browser and perform the test, and reports back with | 8 """Script to actually open a browser and perform the test, and reports back with |
| 9 the result. It uses Selenium WebDriver when possible for running the tests. It | 9 the result. It uses Selenium WebDriver when possible for running the tests. It |
| 10 uses Selenium RC for Safari. | 10 uses Selenium RC for Safari. |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 """Provide the user an informative error message if we attempt to connect to | 134 """Provide the user an informative error message if we attempt to connect to |
| 135 the Selenium remote control server, but cannot access it. Then exit the | 135 the Selenium remote control server, but cannot access it. Then exit the |
| 136 program.""" | 136 program.""" |
| 137 print ('ERROR: Could not connect to Selenium RC server. Are you running' | 137 print ('ERROR: Could not connect to Selenium RC server. Are you running' |
| 138 ' java -jar tools/testing/selenium-server-standalone-*.jar? If not, ' | 138 ' java -jar tools/testing/selenium-server-standalone-*.jar? If not, ' |
| 139 'start it before running this test.') | 139 'start it before running this test.') |
| 140 sys.exit(1) | 140 sys.exit(1) |
| 141 | 141 |
| 142 def start_browser(browser, executable_path, html_out): | 142 def start_browser(browser, executable_path, html_out): |
| 143 if browser == 'chrome': | 143 if browser == 'chrome': |
| 144 script_dir = os.path.dirname(os.path.abspath(__file__)) | |
| 145 crx = os.path.join(script_dir, 'extensions', 'chrome', | |
| 146 'ConsoleCollector.crx') | |
|
eub
2012/10/09 00:17:48
We're not consistent but I think we more often ind
gram
2012/10/09 18:57:14
Done.
| |
| 147 options = selenium.webdriver.chrome.options.Options(); | |
|
eub
2012/10/09 00:17:48
No need for semicolon here and following.
gram
2012/10/09 18:57:14
Done.
| |
| 148 options.add_extension(crx); | |
| 144 # Note: you need ChromeDriver *in your path* to run Chrome, in addition to | 149 # Note: you need ChromeDriver *in your path* to run Chrome, in addition to |
| 145 # installing Chrome. Also note that the build bot runs have a different path | 150 # installing Chrome. Also note that the build bot runs have a different path |
| 146 # from a normal user -- check the build logs. | 151 # from a normal user -- check the build logs. |
| 147 return selenium.webdriver.Chrome() | 152 return selenium.webdriver.Chrome(chrome_options=options); |
| 148 elif browser == 'dartium': | 153 elif browser == 'dartium': |
| 149 script_dir = os.path.dirname(os.path.abspath(__file__)) | 154 script_dir = os.path.dirname(os.path.abspath(__file__)) |
| 150 dartium_dir = os.path.join(script_dir, '..', '..', 'client', 'tests', | 155 dartium_dir = os.path.join(script_dir, '..', '..', 'client', 'tests', |
| 151 'dartium') | 156 'dartium') |
| 157 crx = os.path.join(script_dir, 'extensions', 'chrome', | |
| 158 'ConsoleCollector.crx') | |
|
eub
2012/10/09 00:17:48
+ both of the above comments again, here and below
gram
2012/10/09 18:57:14
Done.
| |
| 152 options = selenium.webdriver.chrome.options.Options() | 159 options = selenium.webdriver.chrome.options.Options() |
| 160 options.add_extension(crx); | |
| 153 # enable ShadowDOM and style scoped for Dartium | 161 # enable ShadowDOM and style scoped for Dartium |
| 154 options.add_argument('--enable-shadow-dom') | 162 options.add_argument('--enable-shadow-dom') |
| 155 options.add_argument('--enable-style-scoped') | 163 options.add_argument('--enable-style-scoped') |
| 156 if executable_path is not None: | 164 if executable_path is not None: |
| 157 options.binary_location = executable_path | 165 options.binary_location = executable_path |
| 158 elif platform.system() == 'Windows': | 166 elif platform.system() == 'Windows': |
| 159 options.binary_location = os.path.join(dartium_dir, 'chrome.exe') | 167 options.binary_location = os.path.join(dartium_dir, 'chrome.exe') |
| 160 elif platform.system() == 'Darwin': | 168 elif platform.system() == 'Darwin': |
| 161 options.binary_location = os.path.join(dartium_dir, 'Chromium.app', | 169 options.binary_location = os.path.join(dartium_dir, 'Chromium.app', |
| 162 'Contents', 'MacOS', 'Chromium') | 170 'Contents', 'MacOS', 'Chromium') |
| 163 else: | 171 else: |
| 164 options.binary_location = os.path.join(dartium_dir, 'chrome') | 172 options.binary_location = os.path.join(dartium_dir, 'chrome') |
| 165 return selenium.webdriver.Chrome(chrome_options=options) | 173 return selenium.webdriver.Chrome(chrome_options=options) |
| 166 elif browser == 'ff': | 174 elif browser == 'ff': |
| 167 script_dir = os.path.dirname(os.path.abspath(__file__)) | 175 script_dir = os.path.dirname(os.path.abspath(__file__)) |
| 168 profile = selenium.webdriver.firefox.firefox_profile.FirefoxProfile() | 176 profile = selenium.webdriver.firefox.firefox_profile.FirefoxProfile() |
| 169 profile.set_preference('dom.max_script_run_time', 0) | 177 profile.set_preference('dom.max_script_run_time', 0) |
| 170 profile.set_preference('dom.max_chrome_script_run_time', 0) | 178 profile.set_preference('dom.max_chrome_script_run_time', 0) |
| 171 profile.set_preference('app.update.auto', True) | 179 profile.set_preference('app.update.auto', True) |
| 172 profile.set_preference('app.update.enabled', True) | 180 profile.set_preference('app.update.enabled', True) |
| 173 xpi = os.path.join(script_dir, 'extensions', 'firefox', 'ConsoleCollector.xpi') | 181 xpi = os.path.join(script_dir, 'extensions', 'firefox', |
| 182 'ConsoleCollector.xpi') | |
| 174 profile.add_extension(xpi); | 183 profile.add_extension(xpi); |
| 175 return selenium.webdriver.Firefox(firefox_profile=profile) | 184 return selenium.webdriver.Firefox(firefox_profile=profile) |
| 176 elif browser == 'ie' and platform.system() == 'Windows': | 185 elif browser == 'ie' and platform.system() == 'Windows': |
| 177 return selenium.webdriver.Ie() | 186 return selenium.webdriver.Ie() |
| 178 elif browser == 'safari' and platform.system() == 'Darwin': | 187 elif browser == 'safari' and platform.system() == 'Darwin': |
| 179 # TODO(efortuna): Ensure our preferences (no pop-up blocking) file is the | 188 # TODO(efortuna): Ensure our preferences (no pop-up blocking) file is the |
| 180 # same (Safari auto-deletes when it has too many "crashes," or in our case, | 189 # same (Safari auto-deletes when it has too many "crashes," or in our case, |
| 181 # timeouts). Come up with a less hacky way to do this. | 190 # timeouts). Come up with a less hacky way to do this. |
| 182 backup_safari_prefs = os.path.dirname(__file__) + '/com.apple.Safari.plist' | 191 backup_safari_prefs = os.path.dirname(__file__) + '/com.apple.Safari.plist' |
| 183 if os.path.exists(backup_safari_prefs): | 192 if os.path.exists(backup_safari_prefs): |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 print 'Content-Type: text/plain\nPASS' | 249 print 'Content-Type: text/plain\nPASS' |
| 241 return 0 | 250 return 0 |
| 242 else: | 251 else: |
| 243 #The hacky way to get document.getElementById('body').innerHTML for this | 252 #The hacky way to get document.getElementById('body').innerHTML for this |
| 244 # webpage, without the JavaScript. | 253 # webpage, without the JavaScript. |
| 245 #TODO(efortuna): Access these elements in a nicer way using DOM parser. | 254 #TODO(efortuna): Access these elements in a nicer way using DOM parser. |
| 246 index = source.find('<body>') | 255 index = source.find('<body>') |
| 247 index += len('<body>') | 256 index += len('<body>') |
| 248 end_index = source.find('</body') | 257 end_index = source.find('</body') |
| 249 print unicode(source[index : end_index]).encode("utf-8") | 258 print unicode(source[index : end_index]).encode("utf-8") |
| 259 logs = [] | |
| 250 if type(browser) is selenium.webdriver.firefox.webdriver.WebDriver: | 260 if type(browser) is selenium.webdriver.firefox.webdriver.WebDriver: |
| 251 logs = browser.execute_script("return window.ConsoleCollector.read()"); | 261 logs = browser.execute_script("return window.ConsoleCollector.read()"); |
| 252 for msg in logs: | 262 elif type(browser) is selenium.webdriver.chrome.webdriver.WebDriver: |
| 253 print('%s:%s:%s:%s %s' %( | 263 browser.set_script_timeout(2000) |
| 254 msg['source'], msg['line'], msg['column'], | 264 logs = browser.execute_async_script( |
| 255 msg['category'], msg['message'])) | 265 "getMessages(arguments[arguments.length-1])"); |
| 266 for msg in logs: | |
| 267 print('%s:%s:%s %s' %( | |
| 268 msg['source'], msg['line'], msg['category'], msg['message'])) | |
| 256 return 1 | 269 return 1 |
| 257 | 270 |
| 258 | 271 |
| 259 def run_batch_tests(): | 272 def run_batch_tests(): |
| 260 ''' | 273 ''' |
| 261 Runs a batch of in-browser tests in the same browser process. Batching | 274 Runs a batch of in-browser tests in the same browser process. Batching |
| 262 gives faster throughput and makes tests less subject to browser starting | 275 gives faster throughput and makes tests less subject to browser starting |
| 263 flakiness, issues with too many browser processes running, etc. | 276 flakiness, issues with too many browser processes running, etc. |
| 264 | 277 |
| 265 When running this function, stdin/stdout is used to communicate with the test | 278 When running this function, stdin/stdout is used to communicate with the test |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 338 browser = start_browser(browser_name, executable_path, html_out) | 351 browser = start_browser(browser_name, executable_path, html_out) |
| 339 | 352 |
| 340 try: | 353 try: |
| 341 output = run_test_in_browser(browser, html_out, timeout, mode) | 354 output = run_test_in_browser(browser, html_out, timeout, mode) |
| 342 return report_results(mode, output, browser) | 355 return report_results(mode, output, browser) |
| 343 finally: | 356 finally: |
| 344 close_browser(browser) | 357 close_browser(browser) |
| 345 | 358 |
| 346 if __name__ == "__main__": | 359 if __name__ == "__main__": |
| 347 sys.exit(main(sys.argv)) | 360 sys.exit(main(sys.argv)) |
| OLD | NEW |