Chromium Code Reviews| Index: tools/testing/run_selenium.py |
| =================================================================== |
| --- tools/testing/run_selenium.py (revision 1463) |
| +++ tools/testing/run_selenium.py (working copy) |
| @@ -5,8 +5,12 @@ |
| # BSD-style license that can be found in the LICENSE file. |
| # |
| -"""Script to actually open browsers and perform the test, and reports back with |
| -the result""" |
| +"""Script to actually open a browser and perform the test, and reports back with |
| +the result. |
| +Expects: |
| + sys.argv[1] = html output file |
| + sys.argv[2] = browser type (default = chrome) |
| +""" |
| import platform |
| import selenium |
| @@ -15,41 +19,39 @@ |
| def runTestInBrowser(browser): |
| + """Run the desired test in the browser, and wait for the test to complete.""" |
| browser.get("file://" + sys.argv[1]) |
| - element = WebDriverWait(browser, 10).until( \ |
| - lambda driver : ('PASS' in driver.page_source) or \ |
| - ('FAIL' in driver.page_source)) |
| - source = browser.page_source |
| - browser.close() |
| + source = '' |
| + try: |
| + element = WebDriverWait(browser, 10).until( \ |
| + lambda driver : ('PASS' in driver.page_source) or \ |
| + ('FAIL' in driver.page_source)) |
| + source = browser.page_source |
| + finally: |
| + # A timeout exception is thrown if nothing happens within the time limit. |
| + browser.close() |
| return source |
| def Main(): |
| - browser = selenium.webdriver.Firefox() # Get local session of firefox |
| - firefox_source = runTestInBrowser(browser) |
| - |
| - # Note: you need ChromeDriver in your path to run chrome, in addition to |
| - #installing Chrome. |
| - # TODO(efortuna): Currently disabled for ease of setup for running on other |
| - # developer machines. Uncomment when frog is robust enough to be tested on |
| - # multiple platforms at once. |
| - #browser = selenium.webdriver.Chrome() |
| - #chrome_source = runTestInBrowser(browser) |
| - |
| - ie_source = '' |
| - if platform.system() == 'Windows': |
| + # Note: you need ChromeDriver *in your path* to run Chrome, in addition to |
| + # installing Chrome. |
| + browser = '' |
|
Siggi Cherem (dart-lang)
2011/11/14 23:56:06
browser = ''
==>
browser = None
Emily Fortuna
2011/11/15 00:38:07
Done.
|
| + if sys.argv[2] == 'chrome': |
| + browser = selenium.webdriver.Chrome() |
| + 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.
|
| + browser = selenium.webdriver.Firefox() |
| + elif sys.argv[2] == 'ie' and platform.system() == 'Windows': |
| 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.
|
| - ie_source = runTestInBrowser(browser) |
| + source = runTestInBrowser(browser) |
| - #TODO(efortuna): Test if all three return correct responses. If not, throw |
| - #error particular to that browser. |
| - if ('PASS' in firefox_source): |
| + if ('PASS' in source): |
| print 'Content-Type: text/plain\nPASS' |
| return 0 |
| else: |
| - index = firefox_source.find('<body>') |
| + index = source.find('<body>') |
| index += len('<body>') |
| - end_index = firefox_source.find('<script') |
| - print firefox_source[index : end_index] |
| + end_index = source.find('<script') |
| + print source[index : end_index] |
| return 1 |