| 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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 else: | 163 else: |
| 164 options.binary_location = os.path.join(dartium_dir, 'chrome') | 164 options.binary_location = os.path.join(dartium_dir, 'chrome') |
| 165 return selenium.webdriver.Chrome(chrome_options=options) | 165 return selenium.webdriver.Chrome(chrome_options=options) |
| 166 elif browser == 'ff': | 166 elif browser == 'ff': |
| 167 script_dir = os.path.dirname(os.path.abspath(__file__)) | 167 script_dir = os.path.dirname(os.path.abspath(__file__)) |
| 168 profile = selenium.webdriver.firefox.firefox_profile.FirefoxProfile() | 168 profile = selenium.webdriver.firefox.firefox_profile.FirefoxProfile() |
| 169 profile.set_preference('dom.max_script_run_time', 0) | 169 profile.set_preference('dom.max_script_run_time', 0) |
| 170 profile.set_preference('dom.max_chrome_script_run_time', 0) | 170 profile.set_preference('dom.max_chrome_script_run_time', 0) |
| 171 profile.set_preference('app.update.auto', True) | 171 profile.set_preference('app.update.auto', True) |
| 172 profile.set_preference('app.update.enabled', True) | 172 profile.set_preference('app.update.enabled', True) |
| 173 xpi = os.path.join(script_dir, 'extensions', 'firefox',
'ConsoleCollector.xpi') | |
| 174 profile.add_extension(xpi); | |
| 175 return selenium.webdriver.Firefox(firefox_profile=profile) | 173 return selenium.webdriver.Firefox(firefox_profile=profile) |
| 176 elif ((browser == 'ie9' or browser == 'ie10') and | 174 elif ((browser == 'ie9' or browser == 'ie10') and |
| 177 platform.system() == 'Windows'): | 175 platform.system() == 'Windows'): |
| 178 return selenium.webdriver.Ie() | 176 return selenium.webdriver.Ie() |
| 179 elif browser == 'safari' and platform.system() == 'Darwin': | 177 elif browser == 'safari' and platform.system() == 'Darwin': |
| 180 # TODO(efortuna): Ensure our preferences (no pop-up blocking) file is the | 178 # TODO(efortuna): Ensure our preferences (no pop-up blocking) file is the |
| 181 # same (Safari auto-deletes when it has too many "crashes," or in our case, | 179 # same (Safari auto-deletes when it has too many "crashes," or in our case, |
| 182 # timeouts). Come up with a less hacky way to do this. | 180 # timeouts). Come up with a less hacky way to do this. |
| 183 backup_safari_prefs = os.path.dirname(__file__) + '/com.apple.Safari.plist' | 181 backup_safari_prefs = os.path.dirname(__file__) + '/com.apple.Safari.plist' |
| 184 if os.path.exists(backup_safari_prefs): | 182 if os.path.exists(backup_safari_prefs): |
| 185 shutil.copy(backup_safari_prefs, | 183 shutil.copy(backup_safari_prefs, |
| 186 '/Library/Preferences/com.apple.Safari.plist') | 184 '/Library/Preferences/com.apple.Safari.plist') |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 print 'Content-Type: text/plain\nPASS' | 236 print 'Content-Type: text/plain\nPASS' |
| 239 return 0 | 237 return 0 |
| 240 else: | 238 else: |
| 241 #The hacky way to get document.getElementById('body').innerHTML for this | 239 #The hacky way to get document.getElementById('body').innerHTML for this |
| 242 # webpage, without the JavaScript. | 240 # webpage, without the JavaScript. |
| 243 #TODO(efortuna): Access these elements in a nicer way using DOM parser. | 241 #TODO(efortuna): Access these elements in a nicer way using DOM parser. |
| 244 index = source.find('<body>') | 242 index = source.find('<body>') |
| 245 index += len('<body>') | 243 index += len('<body>') |
| 246 end_index = source.find('</body') | 244 end_index = source.find('</body') |
| 247 print unicode(source[index : end_index]).encode("utf-8") | 245 print unicode(source[index : end_index]).encode("utf-8") |
| 248 if type(browser) is selenium.webdriver.firefox.webdriver.WebDriver: | |
| 249 logs = browser.execute_script("return window.ConsoleCollector.read()"); | |
| 250 for msg in logs: | |
| 251 print('%s:%s:%s:%s %s' %( | |
| 252 msg['source'], msg['line'], msg['column'], | |
| 253 msg['category'], msg['message'])) | |
| 254 return 1 | 246 return 1 |
| 255 | 247 |
| 256 | 248 |
| 257 def run_batch_tests(): | 249 def run_batch_tests(): |
| 258 ''' | 250 ''' |
| 259 Runs a batch of in-browser tests in the same browser process. Batching | 251 Runs a batch of in-browser tests in the same browser process. Batching |
| 260 gives faster throughput and makes tests less subject to browser starting | 252 gives faster throughput and makes tests less subject to browser starting |
| 261 flakiness, issues with too many browser processes running, etc. | 253 flakiness, issues with too many browser processes running, etc. |
| 262 | 254 |
| 263 When running this function, stdin/stdout is used to communicate with the test | 255 When running this function, stdin/stdout is used to communicate with the test |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 browser = start_browser(browser_name, executable_path, html_out) | 330 browser = start_browser(browser_name, executable_path, html_out) |
| 339 | 331 |
| 340 try: | 332 try: |
| 341 output = run_test_in_browser(browser, html_out, timeout, mode) | 333 output = run_test_in_browser(browser, html_out, timeout, mode) |
| 342 return report_results(mode, output, browser) | 334 return report_results(mode, output, browser) |
| 343 finally: | 335 finally: |
| 344 close_browser(browser) | 336 close_browser(browser) |
| 345 | 337 |
| 346 if __name__ == "__main__": | 338 if __name__ == "__main__": |
| 347 sys.exit(main(sys.argv)) | 339 sys.exit(main(sys.argv)) |
| OLD | NEW |