Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Unified Diff: tools/testing/run_selenium.py

Issue 8670013: Adding the performance and browser benchmarking script. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/testing/run_selenium.py
===================================================================
--- tools/testing/run_selenium.py (revision 1774)
+++ tools/testing/run_selenium.py (working copy)
@@ -10,6 +10,9 @@
Expects:
sys.argv[1] = html output file
sys.argv[2] = browser type (default = chrome)
+ sys.argv[3] = time to wait before timeout
+ sys.argv[4] = is_perf_test -- a boolean indicating if this test is a
Siggi Cherem (dart-lang) 2011/11/23 20:00:29 you might want to use the [optparse] package and m
Emily Fortuna 2011/11/30 00:37:13 Done.
+ performance test. Default (no argument provided) is False.
"""
import platform
@@ -17,15 +20,29 @@
from selenium.webdriver.support.ui import WebDriverWait
import sys
+def perf_test_done(driver):
+ """Tests if the performance test has completed."""
Siggi Cherem (dart-lang) 2011/11/23 20:00:29 Tests -> Checks :)
Emily Fortuna 2011/11/30 00:37:13 Done.
+ #This code is written this way to work around a current instability in the
+ # python webdriver bindings if you call driver.get_element_by_id.
Siggi Cherem (dart-lang) 2011/11/23 20:00:29 strange - remind me to chat about this in person :
+ source = driver.page_source
+ string = '<div id="status">'
+ index = source.find(string)
+ end_index = source.find('</div>', index+1)
+ source = source[index + len(string):end_index]
+ return 'Score:' in source
-def runTestInBrowser(browser):
+def run_test_in_browser(browser):
"""Run the desired test in the browser, and wait for the test to complete."""
browser.get("file://" + sys.argv[1])
source = ''
try:
- element = WebDriverWait(browser, 10).until( \
- lambda driver : ('PASS' in driver.page_source) or \
- ('FAIL' in driver.page_source))
+ if len(sys.argv) > 4:
+ # We're running a performance test.
+ element = WebDriverWait(browser, float(sys.argv[3])).until(perf_test_done)
+ else:
+ element = WebDriverWait(browser, float(sys.argv[3])).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.
@@ -37,24 +54,35 @@
# installing Chrome.
browser = None
if sys.argv[2] == 'chrome':
- browser = selenium.webdriver.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()
else:
raise Exception('Incompatible browser and platform combination.')
- source = runTestInBrowser(browser)
+ source = run_test_in_browser(browser)
- if ('PASS' in source):
- print 'Content-Type: text/plain\nPASS'
- return 0
+ if len(sys.argv) > 4:
+ # We're running a performance test.
+ print source
+ if 'NaN' in source:
+ return 1
+ else:
+ return 0
else:
- index = source.find('<body>')
- index += len('<body>')
- end_index = source.find('<script')
- print source[index : end_index]
- return 1
+ # We're running a correctness test.
+ if ('PASS' in source):
+ print 'Content-Type: text/plain\nPASS'
+ return 0
+ else:
+ #The hacky way to get document.getElementById('body').innerHTML for this
+ # webpage, without the JavaScript.
+ index = source.find('<body>')
+ index += len('<body>')
+ end_index = source.find('<script')
+ print source[index : end_index]
+ return 1
if __name__ == "__main__":
« tools/testing/perf_testing/create_graph.py ('K') | « tools/testing/perf_testing/create_graph.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698