| OLD | NEW |
| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 """Tests to see if our performance test is done by printing a score.""" | 53 """Tests to see if our performance test is done by printing a score.""" |
| 54 #This code is written this way to work around a current instability in the | 54 #This code is written this way to work around a current instability in the |
| 55 # python webdriver bindings if you call driver.get_element_by_id. | 55 # python webdriver bindings if you call driver.get_element_by_id. |
| 56 #TODO(efortuna): Access these elements in a nicer way using DOM parser. | 56 #TODO(efortuna): Access these elements in a nicer way using DOM parser. |
| 57 string = '<div id="status">' | 57 string = '<div id="status">' |
| 58 index = source.find(string) | 58 index = source.find(string) |
| 59 end_index = source.find('</div>', index+1) | 59 end_index = source.find('</div>', index+1) |
| 60 source = source[index + len(string):end_index] | 60 source = source[index + len(string):end_index] |
| 61 return 'Score:' in source | 61 return 'Score:' in source |
| 62 | 62 |
| 63 def dromaeo_test_done(source): | |
| 64 """Tests to see if our performance test is done by printing a score.""" | |
| 65 #TODO(efortuna): Access these elements in a nicer way using DOM parser. | |
| 66 return '<body class="alldone">' in source | |
| 67 | |
| 68 # TODO(vsm): Ideally, this wouldn't live in this file. | 63 # TODO(vsm): Ideally, this wouldn't live in this file. |
| 69 CONFIGURATIONS = { | 64 CONFIGURATIONS = { |
| 70 'correctness': correctness_test_done, | 65 'correctness': correctness_test_done, |
| 71 'perf': perf_test_done, | 66 'perf': perf_test_done |
| 72 'dromaeo': dromaeo_test_done | |
| 73 } | 67 } |
| 74 | 68 |
| 75 def run_test_in_browser(browser, html_out, timeout, mode, refresh): | 69 def run_test_in_browser(browser, html_out, timeout, mode, refresh): |
| 76 """Run the desired test in the browser using Selenium 2.0 WebDriver syntax, | 70 """Run the desired test in the browser using Selenium 2.0 WebDriver syntax, |
| 77 and wait for the test to complete. This is the newer syntax, that currently | 71 and wait for the test to complete. This is the newer syntax, that currently |
| 78 supports Firefox, Chrome, IE, Opera (and some mobile browsers).""" | 72 supports Firefox, Chrome, IE, Opera (and some mobile browsers).""" |
| 79 | 73 |
| 80 if isinstance(browser, selenium.selenium): | 74 if isinstance(browser, selenium.selenium): |
| 81 return run_test_in_browser_selenium_rc(browser, html_out, timeout, mode, | 75 return run_test_in_browser_selenium_rc(browser, html_out, timeout, mode, |
| 82 refresh) | 76 refresh) |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 return | 234 return |
| 241 | 235 |
| 242 # A timeout exception is thrown if nothing happens within the time limit. | 236 # A timeout exception is thrown if nothing happens within the time limit. |
| 243 if (type(browser) is not selenium.webdriver.chrome.webdriver.WebDriver and | 237 if (type(browser) is not selenium.webdriver.chrome.webdriver.WebDriver and |
| 244 type(browser) is not selenium.webdriver.ie.webdriver.WebDriver): | 238 type(browser) is not selenium.webdriver.ie.webdriver.WebDriver): |
| 245 browser.close() | 239 browser.close() |
| 246 | 240 |
| 247 browser.quit() | 241 browser.quit() |
| 248 | 242 |
| 249 def report_results(mode, source, browser): | 243 def report_results(mode, source, browser): |
| 250 # TODO(vsm): Add a failure check for Dromaeo. | |
| 251 if mode != 'correctness': | 244 if mode != 'correctness': |
| 252 # We're running a performance test. | 245 # We're running a performance test. |
| 253 print source.encode('utf8') | 246 print source.encode('utf8') |
| 254 sys.stdout.flush() | 247 sys.stdout.flush() |
| 255 if 'NaN' in source: | 248 if 'NaN' in source: |
| 256 return 1 | 249 return 1 |
| 257 else: | 250 else: |
| 258 return 0 | 251 return 0 |
| 259 else: | 252 else: |
| 260 # We're running a correctness test. Mark test as passing if all individual | 253 # We're running a correctness test. Mark test as passing if all individual |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 browser = start_browser(browser_name, executable_path, html_out) | 381 browser = start_browser(browser_name, executable_path, html_out) |
| 389 | 382 |
| 390 try: | 383 try: |
| 391 output = run_test_in_browser(browser, html_out, timeout, mode, refresh) | 384 output = run_test_in_browser(browser, html_out, timeout, mode, refresh) |
| 392 return report_results(mode, output, browser) | 385 return report_results(mode, output, browser) |
| 393 finally: | 386 finally: |
| 394 close_browser(browser) | 387 close_browser(browser) |
| 395 | 388 |
| 396 if __name__ == "__main__": | 389 if __name__ == "__main__": |
| 397 sys.exit(main(sys.argv)) | 390 sys.exit(main(sys.argv)) |
| OLD | NEW |