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

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

Issue 11406002: Revert run large html tests individually. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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 | « tools/testing/dart/test_suite.dart ('k') | 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 #TODO(efortuna): Access these elements in a nicer way using DOM parser. 64 #TODO(efortuna): Access these elements in a nicer way using DOM parser.
65 return '<body class="alldone">' in source 65 return '<body class="alldone">' in source
66 66
67 # TODO(vsm): Ideally, this wouldn't live in this file. 67 # TODO(vsm): Ideally, this wouldn't live in this file.
68 CONFIGURATIONS = { 68 CONFIGURATIONS = {
69 'correctness': correctness_test_done, 69 'correctness': correctness_test_done,
70 'perf': perf_test_done, 70 'perf': perf_test_done,
71 'dromaeo': dromaeo_test_done 71 'dromaeo': dromaeo_test_done
72 } 72 }
73 73
74 def run_test_in_browser(browser, html_out, timeout, mode, refresh): 74 def run_test_in_browser(browser, html_out, timeout, mode):
75 """Run the desired test in the browser using Selenium 2.0 WebDriver syntax, 75 """Run the desired test in the browser using Selenium 2.0 WebDriver syntax,
76 and wait for the test to complete. This is the newer syntax, that currently 76 and wait for the test to complete. This is the newer syntax, that currently
77 supports Firefox, Chrome, IE, Opera (and some mobile browsers).""" 77 supports Firefox, Chrome, IE, Opera (and some mobile browsers)."""
78 78
79 if isinstance(browser, selenium.selenium): 79 if isinstance(browser, selenium.selenium):
80 return run_test_in_browser_selenium_rc(browser, html_out, timeout, mode, 80 return run_test_in_browser_selenium_rc(browser, html_out, timeout, mode)
81 refresh)
82 81
83 browser.get("file://" + html_out) 82 browser.get("file://" + html_out)
84 if refresh:
85 browser.refresh()
86 try: 83 try:
87 test_done = CONFIGURATIONS[mode] 84 test_done = CONFIGURATIONS[mode]
88 element = WebDriverWait(browser, float(timeout)).until( 85 element = WebDriverWait(browser, float(timeout)).until(
89 lambda driver: test_done(driver.page_source)) 86 lambda driver: test_done(driver.page_source))
90 return browser.page_source 87 return browser.page_source
91 except selenium.common.exceptions.TimeoutException: 88 except selenium.common.exceptions.TimeoutException:
92 return TIMEOUT_ERROR_MSG 89 return TIMEOUT_ERROR_MSG
93 90
94 def run_test_in_browser_selenium_rc(sel, html_out, timeout, mode, refresh): 91 def run_test_in_browser_selenium_rc(sel, html_out, timeout, mode):
95 """ Run the desired test in the browser using Selenium 1.0 syntax, and wait 92 """ Run the desired test in the browser using Selenium 1.0 syntax, and wait
96 for the test to complete. This is used for Safari, since it is not currently 93 for the test to complete. This is used for Safari, since it is not currently
97 supported on Selenium 2.0.""" 94 supported on Selenium 2.0."""
98 sel.open('file://' + html_out) 95 sel.open('file://' + html_out)
99 if refresh:
100 sel.refresh()
101 source = sel.get_html_source() 96 source = sel.get_html_source()
102 end_condition = CONFIGURATIONS[mode] 97 end_condition = CONFIGURATIONS[mode]
103 98
104 elapsed = 0 99 elapsed = 0
105 while (not end_condition(source)) and elapsed <= timeout: 100 while (not end_condition(source)) and elapsed <= timeout:
106 sec = .25 101 sec = .25
107 time.sleep(sec) 102 time.sleep(sec)
108 elapsed += sec 103 elapsed += sec
109 source = sel.get_html_source() 104 source = sel.get_html_source()
110 return source 105 return source
(...skipping 11 matching lines...) Expand all
122 action = 'store', default = None) 117 action = 'store', default = None)
123 # TODO(efortuna): Put this back up to be more than the default timeout in 118 # TODO(efortuna): Put this back up to be more than the default timeout in
124 # test.dart. Right now it needs to be less than 60 so that when test.dart 119 # test.dart. Right now it needs to be less than 60 so that when test.dart
125 # times out, this script also closes the browser windows. 120 # times out, this script also closes the browser windows.
126 parser.add_option('--timeout', dest = 'timeout', 121 parser.add_option('--timeout', dest = 'timeout',
127 help = 'Amount of time (seconds) to wait before timeout', type = 'int', 122 help = 'Amount of time (seconds) to wait before timeout', type = 'int',
128 action = 'store', default=58) 123 action = 'store', default=58)
129 parser.add_option('--mode', dest = 'mode', 124 parser.add_option('--mode', dest = 'mode',
130 help = 'The type of test we are running', 125 help = 'The type of test we are running',
131 action = 'store', default='correctness') 126 action = 'store', default='correctness')
132 parser.add_option('--force-refresh', dest='refresh',
133 help='Force the browser to refresh before getting results from this test '
134 '(used for browser multitests).', action='store_true', default=False)
135 args, _ = parser.parse_args(args=args) 127 args, _ = parser.parse_args(args=args)
136 args.out = args.out.strip('"') 128 args.out = args.out.strip('"')
137 if args.executable and args.browser != 'dartium': 129 if args.executable and args.browser != 'dartium':
138 print 'Executable path only supported when browser=dartium.' 130 print 'Executable path only supported when browser=dartium.'
139 sys.exit(1) 131 sys.exit(1)
140 return (args.out, args.browser, args.executable, args.timeout, args.mode, 132 return args.out, args.browser, args.executable, args.timeout, args.mode
141 args.refresh)
142 133
143 def print_server_error(): 134 def print_server_error():
144 """Provide the user an informative error message if we attempt to connect to 135 """Provide the user an informative error message if we attempt to connect to
145 the Selenium remote control server, but cannot access it. Then exit the 136 the Selenium remote control server, but cannot access it. Then exit the
146 program.""" 137 program."""
147 print ('ERROR: Could not connect to Selenium RC server. Are you running' 138 print ('ERROR: Could not connect to Selenium RC server. Are you running'
148 ' java -jar tools/testing/selenium-server-standalone-*.jar? If not, ' 139 ' java -jar tools/testing/selenium-server-standalone-*.jar? If not, '
149 'start it before running this test.') 140 'start it before running this test.')
150 sys.exit(1) 141 sys.exit(1)
151 142
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 signal.signal(signal.SIGTERM, lambda number, frame: close_browser(browser)) 276 signal.signal(signal.SIGTERM, lambda number, frame: close_browser(browser))
286 277
287 try: 278 try:
288 while True: 279 while True:
289 line = sys.stdin.readline() 280 line = sys.stdin.readline()
290 if line == '--terminate\n': 281 if line == '--terminate\n':
291 print("Terminating selenium driver") 282 print("Terminating selenium driver")
292 break 283 break
293 284
294 (html_out, browser_name, executable_path, 285 (html_out, browser_name, executable_path,
295 timeout, mode, refresh) = parse_args(line.split()) 286 timeout, mode) = parse_args(line.split())
296 287
297 # Sanity checks that test.dart is passing flags we can handle. 288 # Sanity checks that test.dart is passing flags we can handle.
298 if mode != 'correctness': 289 if mode != 'correctness':
299 print 'Batch test runner not compatible with perf testing' 290 print 'Batch test runner not compatible with perf testing'
300 return 1 291 return 1
301 if browser and current_browser_name != browser_name: 292 if browser and current_browser_name != browser_name:
302 print('Batch test runner got multiple browsers: %s and %s' 293 print('Batch test runner got multiple browsers: %s and %s'
303 % (current_browser_name, browser_name)) 294 % (current_browser_name, browser_name))
304 return 1 295 return 1
305 296
306 # Start the browser on the first run 297 # Start the browser on the first run
307 if browser is None: 298 if browser is None:
308 current_browser_name = browser_name 299 current_browser_name = browser_name
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, refresh) 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, browser)
320 if status == 0: 311 if status == 0:
321 print '>>> TEST PASS' 312 print '>>> TEST PASS'
(...skipping 25 matching lines...) Expand all
347 finally: 338 finally:
348 close_output_streams() 339 close_output_streams()
349 340
350 def main(args): 341 def main(args):
351 # Run in batch mode if the --batch flag is passed. 342 # Run in batch mode if the --batch flag is passed.
352 # TODO(jmesserly): reconcile with the existing args parsing 343 # TODO(jmesserly): reconcile with the existing args parsing
353 if '--batch' in args: 344 if '--batch' in args:
354 return run_batch_tests() 345 return run_batch_tests()
355 346
356 # Run a single test 347 # Run a single test
357 html_out, browser_name, executable_path, timeout, mode, refresh = parse_args() 348 html_out, browser_name, executable_path, timeout, mode = parse_args()
358 browser = start_browser(browser_name, executable_path, html_out) 349 browser = start_browser(browser_name, executable_path, html_out)
359 350
360 try: 351 try:
361 output = run_test_in_browser(browser, html_out, timeout, mode, refresh) 352 output = run_test_in_browser(browser, html_out, timeout, mode)
362 return report_results(mode, output, browser) 353 return report_results(mode, output, browser)
363 finally: 354 finally:
364 close_browser(browser) 355 close_browser(browser)
365 356
366 if __name__ == "__main__": 357 if __name__ == "__main__":
367 sys.exit(main(sys.argv)) 358 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « tools/testing/dart/test_suite.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698