Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: dart/tools/testing/run_selenium.py

Issue 11093019: Revert "Experiment: revert parts of r13318." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 options.binary_location = executable_path 157 options.binary_location = executable_path
158 elif platform.system() == 'Windows': 158 elif platform.system() == 'Windows':
159 options.binary_location = os.path.join(dartium_dir, 'chrome.exe') 159 options.binary_location = os.path.join(dartium_dir, 'chrome.exe')
160 elif platform.system() == 'Darwin': 160 elif platform.system() == 'Darwin':
161 options.binary_location = os.path.join(dartium_dir, 'Chromium.app', 161 options.binary_location = os.path.join(dartium_dir, 'Chromium.app',
162 'Contents', 'MacOS', 'Chromium') 162 'Contents', 'MacOS', 'Chromium')
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 profile = selenium.webdriver.firefox.firefox_profile.FirefoxProfile() 168 profile = selenium.webdriver.firefox.firefox_profile.FirefoxProfile()
168 profile.set_preference('dom.max_script_run_time', 0) 169 profile.set_preference('dom.max_script_run_time', 0)
169 profile.set_preference('dom.max_chrome_script_run_time', 0) 170 profile.set_preference('dom.max_chrome_script_run_time', 0)
170 profile.set_preference('app.update.auto', True) 171 profile.set_preference('app.update.auto', True)
171 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);
172 return selenium.webdriver.Firefox(firefox_profile=profile) 175 return selenium.webdriver.Firefox(firefox_profile=profile)
173 elif browser == 'ie' and platform.system() == 'Windows': 176 elif browser == 'ie' and platform.system() == 'Windows':
174 return selenium.webdriver.Ie() 177 return selenium.webdriver.Ie()
175 elif browser == 'safari' and platform.system() == 'Darwin': 178 elif browser == 'safari' and platform.system() == 'Darwin':
176 # TODO(efortuna): Ensure our preferences (no pop-up blocking) file is the 179 # TODO(efortuna): Ensure our preferences (no pop-up blocking) file is the
177 # same (Safari auto-deletes when it has too many "crashes," or in our case, 180 # same (Safari auto-deletes when it has too many "crashes," or in our case,
178 # timeouts). Come up with a less hacky way to do this. 181 # timeouts). Come up with a less hacky way to do this.
179 backup_safari_prefs = os.path.dirname(__file__) + '/com.apple.Safari.plist' 182 backup_safari_prefs = os.path.dirname(__file__) + '/com.apple.Safari.plist'
180 if os.path.exists(backup_safari_prefs): 183 if os.path.exists(backup_safari_prefs):
181 shutil.copy(backup_safari_prefs, 184 shutil.copy(backup_safari_prefs,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 216
214 # A timeout exception is thrown if nothing happens within the time limit. 217 # A timeout exception is thrown if nothing happens within the time limit.
215 if browser != 'chrome': 218 if browser != 'chrome':
216 browser.close() 219 browser.close()
217 try: 220 try:
218 browser.quit() 221 browser.quit()
219 except selenium.common.exceptions.WebDriverException: 222 except selenium.common.exceptions.WebDriverException:
220 # TODO(efortuna): Figure out why this crashes.... and avoid? 223 # TODO(efortuna): Figure out why this crashes.... and avoid?
221 pass 224 pass
222 225
223 def report_results(mode, source): 226 def report_results(mode, source, browser):
224 # TODO(vsm): Add a failure check for Dromaeo. 227 # TODO(vsm): Add a failure check for Dromaeo.
225 if mode != 'correctness': 228 if mode != 'correctness':
226 # We're running a performance test. 229 # We're running a performance test.
227 print source.encode('utf8') 230 print source.encode('utf8')
228 sys.stdout.flush() 231 sys.stdout.flush()
229 if 'NaN' in source: 232 if 'NaN' in source:
230 return 1 233 return 1
231 else: 234 else:
232 return 0 235 return 0
233 else: 236 else:
234 # We're running a correctness test. Mark test as passing if all individual 237 # We're running a correctness test. Mark test as passing if all individual
235 # test cases pass. 238 # test cases pass.
236 if 'FAIL' not in source and 'PASS' in source: 239 if 'FAIL' not in source and 'PASS' in source:
237 print 'Content-Type: text/plain\nPASS' 240 print 'Content-Type: text/plain\nPASS'
238 return 0 241 return 0
239 else: 242 else:
240 #The hacky way to get document.getElementById('body').innerHTML for this 243 #The hacky way to get document.getElementById('body').innerHTML for this
241 # webpage, without the JavaScript. 244 # webpage, without the JavaScript.
242 #TODO(efortuna): Access these elements in a nicer way using DOM parser. 245 #TODO(efortuna): Access these elements in a nicer way using DOM parser.
243 index = source.find('<body>') 246 index = source.find('<body>')
244 index += len('<body>') 247 index += len('<body>')
245 end_index = source.find('</body') 248 end_index = source.find('</body')
246 print unicode(source[index : end_index]).encode("utf-8") 249 print unicode(source[index : end_index]).encode("utf-8")
250 if type(browser) is selenium.webdriver.firefox.webdriver.WebDriver:
251 logs = browser.execute_script("return window.ConsoleCollector.read()");
252 for msg in logs:
253 print('%s:%s:%s:%s %s' %(
254 msg['source'], msg['line'], msg['column'],
255 msg['category'], msg['message']))
247 return 1 256 return 1
248 257
249 258
250 def run_batch_tests(): 259 def run_batch_tests():
251 ''' 260 '''
252 Runs a batch of in-browser tests in the same browser process. Batching 261 Runs a batch of in-browser tests in the same browser process. Batching
253 gives faster throughput and makes tests less subject to browser starting 262 gives faster throughput and makes tests less subject to browser starting
254 flakiness, issues with too many browser processes running, etc. 263 flakiness, issues with too many browser processes running, etc.
255 264
256 When running this function, stdin/stdout is used to communicate with the test 265 When running this function, stdin/stdout is used to communicate with the test
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 browser = start_browser(browser_name, executable_path, html_out) 309 browser = start_browser(browser_name, executable_path, html_out)
301 310
302 source = run_test_in_browser(browser, html_out, timeout, mode) 311 source = run_test_in_browser(browser, html_out, timeout, mode)
303 312
304 # Test is done. Write end token to stderr and flush. 313 # Test is done. Write end token to stderr and flush.
305 sys.stderr.write('>>> EOF STDERR\n') 314 sys.stderr.write('>>> EOF STDERR\n')
306 sys.stderr.flush() 315 sys.stderr.flush()
307 316
308 # print one of: 317 # print one of:
309 # >>> TEST {PASS, FAIL, OK, CRASH, FAIL, TIMEOUT} 318 # >>> TEST {PASS, FAIL, OK, CRASH, FAIL, TIMEOUT}
310 status = report_results(mode, source) 319 status = report_results(mode, source, browser)
311 if status == 0: 320 if status == 0:
312 print '>>> TEST PASS' 321 print '>>> TEST PASS'
313 elif source == TIMEOUT_ERROR_MSG: 322 elif source == TIMEOUT_ERROR_MSG:
314 print '>>> TEST TIMEOUT' 323 print '>>> TEST TIMEOUT'
315 else: 324 else:
316 print '>>> TEST FAIL' 325 print '>>> TEST FAIL'
317 sys.stdout.flush() 326 sys.stdout.flush()
318 finally: 327 finally:
319 print("Closing browser"); 328 print("Closing browser");
320 close_browser(browser) 329 close_browser(browser)
321 330
322 331
323 def main(args): 332 def main(args):
324 # Run in batch mode if the --batch flag is passed. 333 # Run in batch mode if the --batch flag is passed.
325 # TODO(jmesserly): reconcile with the existing args parsing 334 # TODO(jmesserly): reconcile with the existing args parsing
326 if '--batch' in args: 335 if '--batch' in args:
327 return run_batch_tests() 336 return run_batch_tests()
328 337
329 # Run a single test 338 # Run a single test
330 html_out, browser_name, executable_path, timeout, mode = parse_args() 339 html_out, browser_name, executable_path, timeout, mode = parse_args()
331 browser = start_browser(browser_name, executable_path, html_out) 340 browser = start_browser(browser_name, executable_path, html_out)
332 341
333 try: 342 try:
334 output = run_test_in_browser(browser, html_out, timeout, mode) 343 output = run_test_in_browser(browser, html_out, timeout, mode)
335 return report_results(mode, output) 344 return report_results(mode, output, browser)
336 finally: 345 finally:
337 close_browser(browser) 346 close_browser(browser)
338 347
339 if __name__ == "__main__": 348 if __name__ == "__main__":
340 sys.exit(main(sys.argv)) 349 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698