| Index: tools/testing/run_selenium.py
|
| ===================================================================
|
| --- tools/testing/run_selenium.py (revision 1522)
|
| +++ 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,41 @@
|
|
|
|
|
| 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 = None
|
| + if sys.argv[2] == 'chrome':
|
| + browser = selenium.webdriver.Chrome()
|
| + elif sys.argv[2] == 'ff':
|
| + browser = selenium.webdriver.Firefox()
|
| + elif sys.argv[2] == 'ie' and platform.system() == 'Windows':
|
| browser = selenium.webdriver.Ie()
|
| - ie_source = runTestInBrowser(browser)
|
| + else:
|
| + raise Exception('Incompatible browser and platform combination.')
|
| + 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
|
|
|
|
|
|
|