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

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

Issue 9960050: Add runtime=dartium webdriver support to test.dart (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comment Created 8 years, 8 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 | « 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 return source 107 return source
108 108
109 def parse_args(args=None): 109 def parse_args(args=None):
110 parser = optparse.OptionParser() 110 parser = optparse.OptionParser()
111 parser.add_option('--out', dest='out', 111 parser.add_option('--out', dest='out',
112 help = 'The path for html output file that we will running our test from', 112 help = 'The path for html output file that we will running our test from',
113 action = 'store', default = '') 113 action = 'store', default = '')
114 parser.add_option('--browser', dest='browser', 114 parser.add_option('--browser', dest='browser',
115 help = 'The browser type (default = chrome)', 115 help = 'The browser type (default = chrome)',
116 action = 'store', default = 'chrome') 116 action = 'store', default = 'chrome')
117 parser.add_option('--executable', dest='executable',
118 help = 'The browser executable path (only for browser=dartium)',
119 action = 'store', default = None)
117 # TODO(efortuna): Put this back up to be more than the default timeout in 120 # TODO(efortuna): Put this back up to be more than the default timeout in
118 # test.dart. Right now it needs to be less than 60 so that when test.dart 121 # test.dart. Right now it needs to be less than 60 so that when test.dart
119 # times out, this script also closes the browser windows. 122 # times out, this script also closes the browser windows.
120 parser.add_option('--timeout', dest = 'timeout', 123 parser.add_option('--timeout', dest = 'timeout',
121 help = 'Amount of time (seconds) to wait before timeout', type = 'int', 124 help = 'Amount of time (seconds) to wait before timeout', type = 'int',
122 action = 'store', default=58) 125 action = 'store', default=58)
123 parser.add_option('--mode', dest = 'mode', 126 parser.add_option('--mode', dest = 'mode',
124 help = 'The type of test we are running', 127 help = 'The type of test we are running',
125 action = 'store', default='correctness') 128 action = 'store', default='correctness')
126 args, ignored = parser.parse_args(args=args) 129 args, _ = parser.parse_args(args=args)
127 return args.out, args.browser, args.timeout, args.mode 130 if args.executable and args.browser != 'dartium':
131 print 'Executable path only supported when browser=dartium.'
132 sys.exit(1)
133 return args.out, args.browser, args.executable, args.timeout, args.mode
128 134
129 def start_browser(browser, html_out): 135 def start_browser(browser, executable_path, html_out):
130 if browser == 'chrome': 136 if browser == 'chrome':
131 # Note: you need ChromeDriver *in your path* to run Chrome, in addition to 137 # Note: you need ChromeDriver *in your path* to run Chrome, in addition to
132 # installing Chrome. Also note that the build bot runs have a different path 138 # installing Chrome. Also note that the build bot runs have a different path
133 # from a normal user -- check the build logs. 139 # from a normal user -- check the build logs.
134 return selenium.webdriver.Chrome() 140 return selenium.webdriver.Chrome()
135 elif browser == 'dartium': 141 elif browser == 'dartium':
136 script_dir = os.path.dirname(os.path.abspath(__file__)) 142 script_dir = os.path.dirname(os.path.abspath(__file__))
137 dartium_dir = os.path.join(script_dir, '..', '..', 'client', 'tests', 143 dartium_dir = os.path.join(script_dir, '..', '..', 'client', 'tests',
138 'dartium') 144 'dartium')
139 options = selenium.webdriver.chrome.options.Options() 145 options = selenium.webdriver.chrome.options.Options()
140 if platform.system() == 'Windows': 146 if executable_path is not None:
147 options.binary_location = executable_path
148 elif platform.system() == 'Windows':
141 options.binary_location = os.path.join(dartium_dir, 'chrome.exe') 149 options.binary_location = os.path.join(dartium_dir, 'chrome.exe')
142 elif platform.system() == 'Darwin': 150 elif platform.system() == 'Darwin':
143 options.binary_location = os.path.join(dartium_dir, 'Chromium.app', 151 options.binary_location = os.path.join(dartium_dir, 'Chromium.app',
144 'Contents', 'MacOS', 'Chromium') 152 'Contents', 'MacOS', 'Chromium')
145 else: 153 else:
146 options.binary_location = os.path.join(dartium_dir, 'chrome') 154 options.binary_location = os.path.join(dartium_dir, 'chrome')
147 return selenium.webdriver.Chrome(chrome_options=options) 155 return selenium.webdriver.Chrome(chrome_options=options)
148 elif browser == 'ff': 156 elif browser == 'ff':
149 profile = selenium.webdriver.firefox.firefox_profile.FirefoxProfile() 157 profile = selenium.webdriver.firefox.firefox_profile.FirefoxProfile()
150 profile.set_preference('dom.max_script_run_time', 0) 158 profile.set_preference('dom.max_script_run_time', 0)
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 # TODO(jmesserly): It'd be nice to shutdown gracefully in the event of a 250 # TODO(jmesserly): It'd be nice to shutdown gracefully in the event of a
243 # SIGTERM. Unfortunately dart:io cannot send SIGTERM, see dartbug.com/1756. 251 # SIGTERM. Unfortunately dart:io cannot send SIGTERM, see dartbug.com/1756.
244 signal.signal(signal.SIGTERM, lambda number, frame: close_browser(browser)) 252 signal.signal(signal.SIGTERM, lambda number, frame: close_browser(browser))
245 253
246 try: 254 try:
247 while True: 255 while True:
248 line = sys.stdin.readline() 256 line = sys.stdin.readline()
249 if line == '--terminate\n': 257 if line == '--terminate\n':
250 break 258 break
251 259
252 html_out, browser_name, timeout, mode = parse_args(line.split()) 260 (html_out, browser_name, executable_path,
261 timeout, mode) = parse_args(line.split())
253 262
254 # Sanity checks that test.dart is passing flags we can handle. 263 # Sanity checks that test.dart is passing flags we can handle.
255 if mode != 'correctness': 264 if mode != 'correctness':
256 print 'Batch test runner not compatible with perf testing' 265 print 'Batch test runner not compatible with perf testing'
257 return 1 266 return 1
258 if browser and current_browser_name != browser_name: 267 if browser and current_browser_name != browser_name:
259 print('Batch test runner got multiple browsers: %s and %s' 268 print('Batch test runner got multiple browsers: %s and %s'
260 % (current_browser_name, browser_name)) 269 % (current_browser_name, browser_name))
261 return 1 270 return 1
262 271
263 # Start the browser on the first run 272 # Start the browser on the first run
264 if browser is None: 273 if browser is None:
265 current_browser_name = browser_name 274 current_browser_name = browser_name
266 browser = start_browser(browser_name, html_out) 275 browser = start_browser(browser_name, executable_path, html_out)
267 276
268 source = run_test_in_browser(browser, html_out, timeout, mode) 277 source = run_test_in_browser(browser, html_out, timeout, mode)
269 278
270 # Test is done. Write end token to stderr and flush. 279 # Test is done. Write end token to stderr and flush.
271 sys.stderr.write('>>> EOF STDERR\n') 280 sys.stderr.write('>>> EOF STDERR\n')
272 sys.stderr.flush() 281 sys.stderr.flush()
273 282
274 # print one of: 283 # print one of:
275 # >>> TEST {PASS, FAIL, OK, CRASH, FAIL, TIMEOUT} 284 # >>> TEST {PASS, FAIL, OK, CRASH, FAIL, TIMEOUT}
276 status = report_results(mode, source) 285 status = report_results(mode, source)
277 if status == 0: 286 if status == 0:
278 print '>>> TEST PASS' 287 print '>>> TEST PASS'
279 elif source == TIMEOUT_ERROR_MSG: 288 elif source == TIMEOUT_ERROR_MSG:
280 print '>>> TEST TIMEOUT' 289 print '>>> TEST TIMEOUT'
281 else: 290 else:
282 print '>>> TEST FAIL' 291 print '>>> TEST FAIL'
283 sys.stdout.flush() 292 sys.stdout.flush()
284 finally: 293 finally:
285 close_browser(browser) 294 close_browser(browser)
286 295
287 296
288 def main(args): 297 def main(args):
289 # Run in batch mode if the --batch flag is passed. 298 # Run in batch mode if the --batch flag is passed.
290 # TODO(jmesserly): reconcile with the existing args parsing 299 # TODO(jmesserly): reconcile with the existing args parsing
291 if '--batch' in args: 300 if '--batch' in args:
292 return run_batch_tests() 301 return run_batch_tests()
293 302
294 # Run a single test 303 # Run a single test
295 html_out, browser_name, timeout, mode = parse_args() 304 html_out, browser_name, executable_path, timeout, mode = parse_args()
296 browser = start_browser(browser_name, html_out) 305 browser = start_browser(browser_name, executable_path, html_out)
297 306
298 try: 307 try:
299 output = run_test_in_browser(browser, html_out, timeout, mode) 308 output = run_test_in_browser(browser, html_out, timeout, mode)
300 return report_results(mode, output) 309 return report_results(mode, output)
301 finally: 310 finally:
302 close_browser(browser) 311 close_browser(browser)
303 312
304 if __name__ == "__main__": 313 if __name__ == "__main__":
305 sys.exit(main(sys.argv)) 314 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