Chromium Code Reviews| 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 browsers 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 Expects: | |
| 11 sys.argv[1] = html output file | |
| 12 sys.argv[2] = browser type (default = chrome) | |
| 13 """ | |
| 10 | 14 |
| 11 import platform | 15 import platform |
| 12 import selenium | 16 import selenium |
| 13 from selenium.webdriver.support.ui import WebDriverWait | 17 from selenium.webdriver.support.ui import WebDriverWait |
| 14 import sys | 18 import sys |
| 15 | 19 |
| 16 | 20 |
| 17 def runTestInBrowser(browser): | 21 def runTestInBrowser(browser): |
| 22 """Run the desired test in the browser, and wait for the test to complete.""" | |
| 18 browser.get("file://" + sys.argv[1]) | 23 browser.get("file://" + sys.argv[1]) |
| 19 element = WebDriverWait(browser, 10).until( \ | 24 source = '' |
| 20 lambda driver : ('PASS' in driver.page_source) or \ | 25 try: |
| 21 ('FAIL' in driver.page_source)) | 26 element = WebDriverWait(browser, 10).until( \ |
| 22 source = browser.page_source | 27 lambda driver : ('PASS' in driver.page_source) or \ |
| 23 browser.close() | 28 ('FAIL' in driver.page_source)) |
| 29 source = browser.page_source | |
| 30 finally: | |
| 31 # A timeout exception is thrown if nothing happens within the time limit. | |
| 32 browser.close() | |
| 24 return source | 33 return source |
| 25 | 34 |
| 26 def Main(): | 35 def Main(): |
| 27 browser = selenium.webdriver.Firefox() # Get local session of firefox | 36 # Note: you need ChromeDriver *in your path* to run Chrome, in addition to |
| 28 firefox_source = runTestInBrowser(browser) | 37 # installing Chrome. |
| 38 browser = '' | |
|
Siggi Cherem (dart-lang)
2011/11/14 23:56:06
browser = ''
==>
browser = None
Emily Fortuna
2011/11/15 00:38:07
Done.
| |
| 39 if sys.argv[2] == 'chrome': | |
| 40 browser = selenium.webdriver.Chrome() | |
| 41 if sys.argv[2] == 'ff': | |
|
Siggi Cherem (dart-lang)
2011/11/14 23:56:06
if -> elif
Emily Fortuna
2011/11/15 00:38:07
Done.
| |
| 42 browser = selenium.webdriver.Firefox() | |
| 43 elif sys.argv[2] == 'ie' and platform.system() == 'Windows': | |
| 44 browser = selenium.webdriver.Ie() | |
|
Siggi Cherem (dart-lang)
2011/11/14 23:56:06
else error?
Emily Fortuna
2011/11/15 00:38:07
Done.
| |
| 45 source = runTestInBrowser(browser) | |
| 29 | 46 |
| 30 # Note: you need ChromeDriver in your path to run chrome, in addition to | 47 if ('PASS' in source): |
| 31 #installing Chrome. | |
| 32 # TODO(efortuna): Currently disabled for ease of setup for running on other | |
| 33 # developer machines. Uncomment when frog is robust enough to be tested on | |
| 34 # multiple platforms at once. | |
| 35 #browser = selenium.webdriver.Chrome() | |
| 36 #chrome_source = runTestInBrowser(browser) | |
| 37 | |
| 38 ie_source = '' | |
| 39 if platform.system() == 'Windows': | |
| 40 browser = selenium.webdriver.Ie() | |
| 41 ie_source = runTestInBrowser(browser) | |
| 42 | |
| 43 #TODO(efortuna): Test if all three return correct responses. If not, throw | |
| 44 #error particular to that browser. | |
| 45 if ('PASS' in firefox_source): | |
| 46 print 'Content-Type: text/plain\nPASS' | 48 print 'Content-Type: text/plain\nPASS' |
| 47 return 0 | 49 return 0 |
| 48 else: | 50 else: |
| 49 index = firefox_source.find('<body>') | 51 index = source.find('<body>') |
| 50 index += len('<body>') | 52 index += len('<body>') |
| 51 end_index = firefox_source.find('<script') | 53 end_index = source.find('<script') |
| 52 print firefox_source[index : end_index] | 54 print source[index : end_index] |
| 53 return 1 | 55 return 1 |
| 54 | 56 |
| 55 | 57 |
| 56 if __name__ == "__main__": | 58 if __name__ == "__main__": |
| 57 sys.exit(Main()) | 59 sys.exit(Main()) |
| OLD | NEW |