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

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

Issue 11368128: Take 2 of splitting html tests into subtests. Had to make two changes to drt to (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
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): 74 def run_test_in_browser(browser, html_out, timeout, mode, refresh):
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)
81 82
82 browser.get("file://" + html_out) 83 browser.get(html_out)
84 if refresh:
85 browser.refresh()
83 try: 86 try:
84 test_done = CONFIGURATIONS[mode] 87 test_done = CONFIGURATIONS[mode]
85 element = WebDriverWait(browser, float(timeout)).until( 88 element = WebDriverWait(browser, float(timeout)).until(
86 lambda driver: test_done(driver.page_source)) 89 lambda driver: test_done(driver.page_source))
87 return browser.page_source 90 return browser.page_source
88 except selenium.common.exceptions.TimeoutException: 91 except selenium.common.exceptions.TimeoutException:
89 return TIMEOUT_ERROR_MSG 92 return TIMEOUT_ERROR_MSG
90 93
91 def run_test_in_browser_selenium_rc(sel, html_out, timeout, mode): 94 def run_test_in_browser_selenium_rc(sel, html_out, timeout, mode, refresh):
92 """ Run the desired test in the browser using Selenium 1.0 syntax, and wait 95 """ Run the desired test in the browser using Selenium 1.0 syntax, and wait
93 for the test to complete. This is used for Safari, since it is not currently 96 for the test to complete. This is used for Safari, since it is not currently
94 supported on Selenium 2.0.""" 97 supported on Selenium 2.0."""
95 sel.open('file://' + html_out) 98 sel.open(html_out)
99 if refresh:
100 sel.refresh()
96 source = sel.get_html_source() 101 source = sel.get_html_source()
97 end_condition = CONFIGURATIONS[mode] 102 end_condition = CONFIGURATIONS[mode]
98 103
99 elapsed = 0 104 elapsed = 0
100 while (not end_condition(source)) and elapsed <= timeout: 105 while (not end_condition(source)) and elapsed <= timeout:
101 sec = .25 106 sec = .25
102 time.sleep(sec) 107 time.sleep(sec)
103 elapsed += sec 108 elapsed += sec
104 source = sel.get_html_source() 109 source = sel.get_html_source()
105 return source 110 return source
(...skipping 11 matching lines...) Expand all
117 action = 'store', default = None) 122 action = 'store', default = None)
118 # TODO(efortuna): Put this back up to be more than the default timeout in 123 # TODO(efortuna): Put this back up to be more than the default timeout in
119 # test.dart. Right now it needs to be less than 60 so that when test.dart 124 # test.dart. Right now it needs to be less than 60 so that when test.dart
120 # times out, this script also closes the browser windows. 125 # times out, this script also closes the browser windows.
121 parser.add_option('--timeout', dest = 'timeout', 126 parser.add_option('--timeout', dest = 'timeout',
122 help = 'Amount of time (seconds) to wait before timeout', type = 'int', 127 help = 'Amount of time (seconds) to wait before timeout', type = 'int',
123 action = 'store', default=58) 128 action = 'store', default=58)
124 parser.add_option('--mode', dest = 'mode', 129 parser.add_option('--mode', dest = 'mode',
125 help = 'The type of test we are running', 130 help = 'The type of test we are running',
126 action = 'store', default='correctness') 131 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)
127 args, _ = parser.parse_args(args=args) 135 args, _ = parser.parse_args(args=args)
128 args.out = args.out.strip('"') 136 args.out = args.out.strip('"')
129 if args.executable and args.browser != 'dartium': 137 if args.executable and args.browser != 'dartium':
130 print 'Executable path only supported when browser=dartium.' 138 print 'Executable path only supported when browser=dartium.'
131 sys.exit(1) 139 sys.exit(1)
132 return args.out, args.browser, args.executable, args.timeout, args.mode 140 return (args.out, args.browser, args.executable, args.timeout, args.mode,
141 args.refresh)
133 142
134 def print_server_error(): 143 def print_server_error():
135 """Provide the user an informative error message if we attempt to connect to 144 """Provide the user an informative error message if we attempt to connect to
136 the Selenium remote control server, but cannot access it. Then exit the 145 the Selenium remote control server, but cannot access it. Then exit the
137 program.""" 146 program."""
138 print ('ERROR: Could not connect to Selenium RC server. Are you running' 147 print ('ERROR: Could not connect to Selenium RC server. Are you running'
139 ' java -jar tools/testing/selenium-server-standalone-*.jar? If not, ' 148 ' java -jar tools/testing/selenium-server-standalone-*.jar? If not, '
140 'start it before running this test.') 149 'start it before running this test.')
141 sys.exit(1) 150 sys.exit(1)
142 151
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 platform.system() == 'Windows'): 185 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):
184 shutil.copy(backup_safari_prefs, 193 shutil.copy(backup_safari_prefs,
185 '/Library/Preferences/com.apple.Safari.plist') 194 '/Library/Preferences/com.apple.Safari.plist')
186 sel = selenium.selenium('localhost', 4444, "*safari", 'file://' + html_out) 195 sel = selenium.selenium('localhost', 4444, "*safari", html_out)
187 try: 196 try:
188 sel.start() 197 sel.start()
189 return sel 198 return sel
190 except socket.error: 199 except socket.error:
191 print_server_error() 200 print_server_error()
192 elif browser == 'opera': 201 elif browser == 'opera':
193 try: 202 try:
194 driver = RemoteWebDriver(desired_capabilities=DesiredCapabilities.OPERA) 203 driver = RemoteWebDriver(desired_capabilities=DesiredCapabilities.OPERA)
195 # By default, Opera sets their script timeout (the amount of time they 204 # By default, Opera sets their script timeout (the amount of time they
196 # expect to hear back from the JavaScript file) to be 10 seconds. We just 205 # expect to hear back from the JavaScript file) to be 10 seconds. We just
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 signal.signal(signal.SIGTERM, lambda number, frame: close_browser(browser)) 285 signal.signal(signal.SIGTERM, lambda number, frame: close_browser(browser))
277 286
278 try: 287 try:
279 while True: 288 while True:
280 line = sys.stdin.readline() 289 line = sys.stdin.readline()
281 if line == '--terminate\n': 290 if line == '--terminate\n':
282 print("Terminating selenium driver") 291 print("Terminating selenium driver")
283 break 292 break
284 293
285 (html_out, browser_name, executable_path, 294 (html_out, browser_name, executable_path,
286 timeout, mode) = parse_args(line.split()) 295 timeout, mode, refresh) = parse_args(line.split())
287 296
288 # Sanity checks that test.dart is passing flags we can handle. 297 # Sanity checks that test.dart is passing flags we can handle.
289 if mode != 'correctness': 298 if mode != 'correctness':
290 print 'Batch test runner not compatible with perf testing' 299 print 'Batch test runner not compatible with perf testing'
291 return 1 300 return 1
292 if browser and current_browser_name != browser_name: 301 if browser and current_browser_name != browser_name:
293 print('Batch test runner got multiple browsers: %s and %s' 302 print('Batch test runner got multiple browsers: %s and %s'
294 % (current_browser_name, browser_name)) 303 % (current_browser_name, browser_name))
295 return 1 304 return 1
296 305
297 # Start the browser on the first run 306 # Start the browser on the first run
298 if browser is None: 307 if browser is None:
299 current_browser_name = browser_name 308 current_browser_name = browser_name
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, refresh)
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, browser) 319 status = report_results(mode, source, browser)
311 if status == 0: 320 if status == 0:
312 print '>>> TEST PASS' 321 print '>>> TEST PASS'
(...skipping 25 matching lines...) Expand all
338 finally: 347 finally:
339 close_output_streams() 348 close_output_streams()
340 349
341 def main(args): 350 def main(args):
342 # Run in batch mode if the --batch flag is passed. 351 # Run in batch mode if the --batch flag is passed.
343 # TODO(jmesserly): reconcile with the existing args parsing 352 # TODO(jmesserly): reconcile with the existing args parsing
344 if '--batch' in args: 353 if '--batch' in args:
345 return run_batch_tests() 354 return run_batch_tests()
346 355
347 # Run a single test 356 # Run a single test
348 html_out, browser_name, executable_path, timeout, mode = parse_args() 357 html_out, browser_name, executable_path, timeout, mode, refresh = parse_args()
349 browser = start_browser(browser_name, executable_path, html_out) 358 browser = start_browser(browser_name, executable_path, html_out)
350 359
351 try: 360 try:
352 output = run_test_in_browser(browser, html_out, timeout, mode) 361 output = run_test_in_browser(browser, html_out, timeout, mode, refresh)
353 return report_results(mode, output, browser) 362 return report_results(mode, output, browser)
354 finally: 363 finally:
355 close_browser(browser) 364 close_browser(browser)
356 365
357 if __name__ == "__main__": 366 if __name__ == "__main__":
358 sys.exit(main(sys.argv)) 367 sys.exit(main(sys.argv))
OLDNEW
« tools/testing/dart/test_suite.dart ('K') | « tools/testing/drt-trampoline.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698