| 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. | 9 the result. |
| 10 """ | 10 """ |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 if is_perf: | 42 if is_perf: |
| 43 # We're running a performance test. | 43 # We're running a performance test. |
| 44 element = WebDriverWait(browser, float(timeout)).until(perf_test_done) | 44 element = WebDriverWait(browser, float(timeout)).until(perf_test_done) |
| 45 else: | 45 else: |
| 46 element = WebDriverWait(browser, float(timeout)).until( | 46 element = WebDriverWait(browser, float(timeout)).until( |
| 47 lambda driver : ('PASS' in driver.page_source) or | 47 lambda driver : ('PASS' in driver.page_source) or |
| 48 ('FAIL' in driver.page_source)) | 48 ('FAIL' in driver.page_source)) |
| 49 source = browser.page_source | 49 source = browser.page_source |
| 50 finally: | 50 finally: |
| 51 # A timeout exception is thrown if nothing happens within the time limit. | 51 # A timeout exception is thrown if nothing happens within the time limit. |
| 52 browser.close() | 52 if browser != 'chrome': |
| 53 browser.quit() | 53 browser.close() |
| 54 try: |
| 55 browser.quit() |
| 56 except selenium.common.exceptions.WebDriverException: |
| 57 #TODO(efortuna): figure out why this crashes.... and avoid? |
| 58 pass |
| 54 return source | 59 return source |
| 55 | 60 |
| 56 def run_test_in_browser_selenium1(sel, html_out, timeout, is_perf): | 61 def run_test_in_browser_selenium1(sel, html_out, timeout, is_perf): |
| 57 """ Run the desired test in the browser using Selenium 1.0 syntax, and wait | 62 """ Run the desired test in the browser using Selenium 1.0 syntax, and wait |
| 58 for the test to complete. This is used for Safari, since it is not currently | 63 for the test to complete. This is used for Safari, since it is not currently |
| 59 supported on Selenium 2.0.""" | 64 supported on Selenium 2.0.""" |
| 60 sel.open('file://' + html_out) | 65 sel.open('file://' + html_out) |
| 61 source = sel.get_html_source() | 66 source = sel.get_html_source() |
| 62 def end_condition(source): | 67 def end_condition(source): |
| 63 return 'PASS' in source and 'FAIL' in source | 68 return 'PASS' in source or 'FAIL' in source |
| 64 if is_perf: | 69 if is_perf: |
| 65 end_condition = perf_test_done_helper | 70 end_condition = perf_test_done_helper |
| 66 | 71 |
| 67 elapsed = 0 | 72 elapsed = 0 |
| 68 while (not end_condition(source)) and elapsed <= timeout: | 73 while (not end_condition(source)) and elapsed <= timeout: |
| 69 sec = .25 | 74 sec = .25 |
| 70 time.sleep(sec) | 75 time.sleep(sec) |
| 71 elapsed += sec | 76 elapsed += sec |
| 72 source = sel.get_html_source() | 77 source = sel.get_html_source() |
| 73 sel.stop() | 78 sel.stop() |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 #TODO(efortuna): Access these elements in a nicer way using DOM parser. | 142 #TODO(efortuna): Access these elements in a nicer way using DOM parser. |
| 138 index = source.find('<body>') | 143 index = source.find('<body>') |
| 139 index += len('<body>') | 144 index += len('<body>') |
| 140 end_index = source.find('<script') | 145 end_index = source.find('<script') |
| 141 print source[index : end_index] | 146 print source[index : end_index] |
| 142 return 1 | 147 return 1 |
| 143 | 148 |
| 144 | 149 |
| 145 if __name__ == "__main__": | 150 if __name__ == "__main__": |
| 146 sys.exit(Main()) | 151 sys.exit(Main()) |
| OLD | NEW |