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

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

Issue 11086021: 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__))
168 profile = selenium.webdriver.firefox.firefox_profile.FirefoxProfile() 167 profile = selenium.webdriver.firefox.firefox_profile.FirefoxProfile()
169 profile.set_preference('dom.max_script_run_time', 0) 168 profile.set_preference('dom.max_script_run_time', 0)
170 profile.set_preference('dom.max_chrome_script_run_time', 0) 169 profile.set_preference('dom.max_chrome_script_run_time', 0)
171 profile.set_preference('app.update.auto', True) 170 profile.set_preference('app.update.auto', True)
172 profile.set_preference('app.update.enabled', True) 171 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) 172 return selenium.webdriver.Firefox(firefox_profile=profile)
176 elif browser == 'ie' and platform.system() == 'Windows': 173 elif browser == 'ie' and platform.system() == 'Windows':
177 return selenium.webdriver.Ie() 174 return selenium.webdriver.Ie()
178 elif browser == 'safari' and platform.system() == 'Darwin': 175 elif browser == 'safari' and platform.system() == 'Darwin':
179 # TODO(efortuna): Ensure our preferences (no pop-up blocking) file is the 176 # 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, 177 # 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. 178 # timeouts). Come up with a less hacky way to do this.
182 backup_safari_prefs = os.path.dirname(__file__) + '/com.apple.Safari.plist' 179 backup_safari_prefs = os.path.dirname(__file__) + '/com.apple.Safari.plist'
183 if os.path.exists(backup_safari_prefs): 180 if os.path.exists(backup_safari_prefs):
184 shutil.copy(backup_safari_prefs, 181 shutil.copy(backup_safari_prefs,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 213
217 # A timeout exception is thrown if nothing happens within the time limit. 214 # A timeout exception is thrown if nothing happens within the time limit.
218 if browser != 'chrome': 215 if browser != 'chrome':
219 browser.close() 216 browser.close()
220 try: 217 try:
221 browser.quit() 218 browser.quit()
222 except selenium.common.exceptions.WebDriverException: 219 except selenium.common.exceptions.WebDriverException:
223 # TODO(efortuna): Figure out why this crashes.... and avoid? 220 # TODO(efortuna): Figure out why this crashes.... and avoid?
224 pass 221 pass
225 222
226 def report_results(mode, source, browser): 223 def report_results(mode, source):
227 # TODO(vsm): Add a failure check for Dromaeo. 224 # TODO(vsm): Add a failure check for Dromaeo.
228 if mode != 'correctness': 225 if mode != 'correctness':
229 # We're running a performance test. 226 # We're running a performance test.
230 print source.encode('utf8') 227 print source.encode('utf8')
231 sys.stdout.flush() 228 sys.stdout.flush()
232 if 'NaN' in source: 229 if 'NaN' in source:
233 return 1 230 return 1
234 else: 231 else:
235 return 0 232 return 0
236 else: 233 else:
237 # We're running a correctness test. Mark test as passing if all individual 234 # We're running a correctness test. Mark test as passing if all individual
238 # test cases pass. 235 # test cases pass.
239 if 'FAIL' not in source and 'PASS' in source: 236 if 'FAIL' not in source and 'PASS' in source:
240 print 'Content-Type: text/plain\nPASS' 237 print 'Content-Type: text/plain\nPASS'
241 return 0 238 return 0
242 else: 239 else:
243 #The hacky way to get document.getElementById('body').innerHTML for this 240 #The hacky way to get document.getElementById('body').innerHTML for this
244 # webpage, without the JavaScript. 241 # webpage, without the JavaScript.
245 #TODO(efortuna): Access these elements in a nicer way using DOM parser. 242 #TODO(efortuna): Access these elements in a nicer way using DOM parser.
246 index = source.find('<body>') 243 index = source.find('<body>')
247 index += len('<body>') 244 index += len('<body>')
248 end_index = source.find('</body') 245 end_index = source.find('</body')
249 print unicode(source[index : end_index]).encode("utf-8") 246 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']))
256 return 1 247 return 1
257 248
258 249
259 def run_batch_tests(): 250 def run_batch_tests():
260 ''' 251 '''
261 Runs a batch of in-browser tests in the same browser process. Batching 252 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 253 gives faster throughput and makes tests less subject to browser starting
263 flakiness, issues with too many browser processes running, etc. 254 flakiness, issues with too many browser processes running, etc.
264 255
265 When running this function, stdin/stdout is used to communicate with the test 256 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
309 browser = start_browser(browser_name, executable_path, html_out) 300 browser = start_browser(browser_name, executable_path, html_out)
310 301
311 source = run_test_in_browser(browser, html_out, timeout, mode) 302 source = run_test_in_browser(browser, html_out, timeout, mode)
312 303
313 # Test is done. Write end token to stderr and flush. 304 # Test is done. Write end token to stderr and flush.
314 sys.stderr.write('>>> EOF STDERR\n') 305 sys.stderr.write('>>> EOF STDERR\n')
315 sys.stderr.flush() 306 sys.stderr.flush()
316 307
317 # print one of: 308 # print one of:
318 # >>> TEST {PASS, FAIL, OK, CRASH, FAIL, TIMEOUT} 309 # >>> TEST {PASS, FAIL, OK, CRASH, FAIL, TIMEOUT}
319 status = report_results(mode, source, browser) 310 status = report_results(mode, source)
320 if status == 0: 311 if status == 0:
321 print '>>> TEST PASS' 312 print '>>> TEST PASS'
322 elif source == TIMEOUT_ERROR_MSG: 313 elif source == TIMEOUT_ERROR_MSG:
323 print '>>> TEST TIMEOUT' 314 print '>>> TEST TIMEOUT'
324 else: 315 else:
325 print '>>> TEST FAIL' 316 print '>>> TEST FAIL'
326 sys.stdout.flush() 317 sys.stdout.flush()
327 finally: 318 finally:
328 print("Closing browser"); 319 print("Closing browser");
329 close_browser(browser) 320 close_browser(browser)
330 321
331 322
332 def main(args): 323 def main(args):
333 # Run in batch mode if the --batch flag is passed. 324 # Run in batch mode if the --batch flag is passed.
334 # TODO(jmesserly): reconcile with the existing args parsing 325 # TODO(jmesserly): reconcile with the existing args parsing
335 if '--batch' in args: 326 if '--batch' in args:
336 return run_batch_tests() 327 return run_batch_tests()
337 328
338 # Run a single test 329 # Run a single test
339 html_out, browser_name, executable_path, timeout, mode = parse_args() 330 html_out, browser_name, executable_path, timeout, mode = parse_args()
340 browser = start_browser(browser_name, executable_path, html_out) 331 browser = start_browser(browser_name, executable_path, html_out)
341 332
342 try: 333 try:
343 output = run_test_in_browser(browser, html_out, timeout, mode) 334 output = run_test_in_browser(browser, html_out, timeout, mode)
344 return report_results(mode, output, browser) 335 return report_results(mode, output)
345 finally: 336 finally:
346 close_browser(browser) 337 close_browser(browser)
347 338
348 if __name__ == "__main__": 339 if __name__ == "__main__":
349 sys.exit(main(sys.argv)) 340 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