diff options
author | gspencer@google.com <gspencer@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-03 00:39:32 +0000 |
---|---|---|
committer | gspencer@google.com <gspencer@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-03 00:39:32 +0000 |
commit | 17fb8c85b6323934cab80d71d3c583710e937303 (patch) | |
tree | 5e53f1df31663c0b752634ff8a8194f23d68e051 /o3d | |
parent | 755165a7277c36b7f542e6cc8b0188479549a63b (diff) | |
download | chromium_src-17fb8c85b6323934cab80d71d3c583710e937303.zip chromium_src-17fb8c85b6323934cab80d71d3c583710e937303.tar.gz chromium_src-17fb8c85b6323934cab80d71d3c583710e937303.tar.bz2 |
This changes the selenium driver script to not be so scons-specific, and
makes it so that it will self-locate some of the things it needs (for instance,
it no longer needs to have PYTHONPATH env var set correctly -- it'll find
the third party dir relative to itself and add gflags to the path).
As part of this, it now copies the selenium tests into the artifacts directory
so it can run them out of that directory instead of from the source dir. This
is so that we can use the product dir as the root of the http server, since
in GYP all three platforms have different locations for their output, and
different working directories during the build.
Review URL: http://codereview.chromium.org/180074
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25288 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d')
-rw-r--r-- | o3d/tests/build.scons | 23 | ||||
-rw-r--r-- | o3d/tests/selenium/main.py | 75 | ||||
-rw-r--r-- | o3d/tests/selenium/selenium_constants.py | 15 |
3 files changed, 79 insertions, 34 deletions
diff --git a/o3d/tests/build.scons b/o3d/tests/build.scons index f1e4b8a..73dc3ef 100644 --- a/o3d/tests/build.scons +++ b/o3d/tests/build.scons @@ -540,10 +540,10 @@ run_env.Replace( len(run_env.subst('$SCONSTRUCT_DIR')):], SELENIUM_FLAGS = ('--verbose=$SELENIUM_VERBOSE ' '--selenium_server="$SELENIUM_SERVER_JAR" ' + '--product_dir="$ARTIFACTS_DIR" ' '--testprefix=$SELENIUM_TEST_PREFIX ' '--testsuffixes=$SELENIUM_TEST_SUFFIXES ' '--screencompare=$PDIFF_PATH ' - '--samplespath=$SELENIUM_SAMPLES_DIR ' '$SELENIUM_CAPTURE_SCREENSHOTS ' '$SELENIUM_EXTRA_FLAGS'), ) @@ -615,6 +615,24 @@ if run_env.Bit('mac'): 'rm -rf "$MAC_FIREFOX_DIR"', ] +def DeferSeleniumTestsInstall(env): + manifest = [] + sconstruct_dir = env.subst('$SCONSTRUCT_DIR') + for root, dirs, files in \ + os.walk(sconstruct_dir + '/tests/selenium/tests'): + if '.svn' in dirs: + dirs.remove('.svn') + for file in files: + manifest.append(os.path.join(root[len(sconstruct_dir) + 1:], file)) + for manifest_item in manifest: + result = env.Command('$ARTIFACTS_DIR/' + manifest_item, + '$MAIN_DIR/' + manifest_item, + [Delete('$TARGET'), + Copy('$TARGET', '$SOURCE'), + Chmod('$TARGET', 0777)]) + env.Publish('selenium', 'tests', result); + +env.Defer(DeferSeleniumTestsInstall) def DeferSelenium(env): if not selenium_good_to_go: @@ -625,7 +643,8 @@ def DeferSelenium(env): else: run_selenium_firefox = run_env.Alias( 'selenium_firefox', - [plugin_path, env.GetPublished('samples', 'asset_files')], + [plugin_path, env.GetPublished('samples', 'asset_files'), + env.GetPublished('selenium', 'tests')], # TODO: have a cleaner way to do this. [Delete('$ARTIFACTS_DIR/selenium/screenshots_firefox'), Mkdir('$ARTIFACTS_DIR/selenium/screenshots_firefox')] + diff --git a/o3d/tests/selenium/main.py b/o3d/tests/selenium/main.py index 5ac135a..b421659 100644 --- a/o3d/tests/selenium/main.py +++ b/o3d/tests/selenium/main.py @@ -38,16 +38,24 @@ Launches browsers to test the local build of the o3d plugin and reports results back to the user. """ +import os +import sys +script_dir = os.path.normpath(os.path.dirname(os.path.abspath(__file__))) +o3d_dir = os.path.dirname(os.path.dirname(script_dir)) +src_dir = os.path.dirname(o3d_dir) +third_party_dir = os.path.join(src_dir, 'third_party') +gflags_dir = os.path.join(third_party_dir, 'gflags', 'python') +selenium_dir = os.path.join(third_party_dir, 'selenium_rc', 'files') +selenium_py_dir = os.path.join(selenium_dir, 'selenium-python-client-driver') +sys.path.append(gflags_dir) +sys.path.append(selenium_py_dir) -import os -import platform import re import SimpleHTTPServer import socket import SocketServer import subprocess -import sys import threading import time import unittest @@ -60,13 +68,12 @@ import samples_tests import selenium_constants import selenium_utilities - -if platform.system() == "Windows": +if sys.platform == 'win32' or sys.platform == 'cygwin': default_java_exe = "java.exe" else: default_java_exe = "java" -# Commands line flags +# Command line flags FLAGS = gflags.FLAGS gflags.DEFINE_boolean("verbose", False, "verbosity") gflags.DEFINE_boolean("screenshots", False, "takes screenshots") @@ -76,9 +83,13 @@ gflags.DEFINE_string( "specifies the path to the java executable.") gflags.DEFINE_string( "selenium_server", - "", + os.path.join(selenium_dir, 'selenium-server', 'selenium-server.jar'), "specifies the path to the selenium server jar.") gflags.DEFINE_string( + "product_dir", + None, + "specifies the path to the build output directory.") +gflags.DEFINE_string( "screencompare", "", "specifies the directory in which perceptualdiff resides.\n" @@ -95,10 +106,12 @@ gflags.DEFINE_string( "testprefix", "Test", "specifies the prefix of tests to run") gflags.DEFINE_string( - "testsuffixes", "", + "testsuffixes", + "small,medium,large", "specifies the suffixes, separated by commas of tests to run") gflags.DEFINE_string( - "servertimeout", "30", + "servertimeout", + "30", "Specifies the timeout value, in seconds, for the selenium server.") # Browsers to choose from (for browser flag). @@ -117,11 +130,8 @@ gflags.DEFINE_string( "(for platforms that don't support MOZ_PLUGIN_PATH)") gflags.DEFINE_string( "samplespath", - "/", - "specifies the path from the web root to the samples." - "eg. 'scons-out/test-dbg-d3d/artifacts'") - -TESTING_ROOT = os.path.abspath(os.path.dirname(__file__) + "/..") + "", + "specifies the path from the web root to the samples.") class MyRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): @@ -366,8 +376,7 @@ class SeleniumSession(object): # Start up a static file server, to serve the test pages. if not http_root: - # Serve from the o3d directory - http_root = TESTING_ROOT + "/../" + http_root = FLAGS.product_dir self.http_server = LocalFileHTTPServer.StartServer(http_root) @@ -403,10 +412,11 @@ class SeleniumSession(object): else: server_url = "http://localhost:" server_url += str(self.http_server.http_port) - browser_path_with_space = FLAGS.browserpath - if browser_path_with_space: - browser_path_with_space = " " + browser_path_with_space + browser_path_with_space = "" + if FLAGS.browserpath: + browser_path_with_space = " " + FLAGS.browserpath + self.session = selenium.selenium("localhost", self.selenium_server.selenium_port, browser + browser_path_with_space, @@ -572,7 +582,7 @@ def SeleniumSuite(session, browser, test_list, test_prefix, test_suffixes): suffixes = test_suffixes.split(",") # add sample tests. - filename = os.path.join(os.getcwd(), "tests", "selenium", "sample_list.txt") + filename = os.path.abspath(os.path.join(script_dir, "sample_list.txt")) AddTests(test_suite, session, browser, @@ -584,8 +594,8 @@ def SeleniumSuite(session, browser, test_list, test_prefix, test_suffixes): FLAGS.samplespath.replace("\\", "/")) # add javascript tests. - filename = os.path.join(os.getcwd(), "tests", "selenium", - "javascript_unit_test_list.txt") + filename = os.path.abspath(os.path.join(script_dir, + "javascript_unit_test_list.txt")) AddTests(test_suite, session, browser, @@ -806,13 +816,13 @@ def CompareScreenshots(browser, test_list, screencompare, screenshotsdir, if opt.startswith("pdiff_threshold"): pixel_threshold = selenium_utilities.GetArgument(opt) elif (opt.startswith("pdiff_threshold_mac") and - platform.system() == "Darwin"): + sys.platform == "darwin"): pixel_threshold = selenium_utilities.GetArgument(opt) elif (opt.startswith("pdiff_threshold_win") and - platform.system() == "Microsoft"): + sys.platform == 'win32' or sys.platform == "cygwin"): pixel_threshold = selenium_utilities.GetArgument(opt) elif (opt.startswith("pdiff_threshold_linux") and - platform.system() == "Linux"): + sys.platform[:5] == "linux"): pixel_threshold = selenium_utilities.GetArgument(opt) elif (opt.startswith("colorfactor")): colorfactor = selenium_utilities.GetArgument(opt) @@ -938,7 +948,7 @@ def main(unused_argv): # Open a new session to Selenium Remote Control selenium_session = SeleniumSession(FLAGS.verbose, FLAGS.java, - FLAGS.selenium_server, + os.path.abspath(FLAGS.selenium_server), FLAGS.servertimeout) if not selenium_session.http_server or not selenium_session.selenium_server: return 1 @@ -984,4 +994,17 @@ def main(unused_argv): if __name__ == "__main__": remaining_argv = FLAGS(sys.argv) + + # Setup the environment for Firefox + os.environ["MOZ_CRASHREPORTER_DISABLE"] = "1" + os.environ["MOZ_PLUGIN_PATH"] = os.path.normpath(FLAGS.product_dir) + + # Setup the LD_LIBRARY_PATH on Linux. + if sys.platform[:5] == "linux": + if os.environ.get("LD_LIBRARY_PATH"): + os.environ["LD_LIBRARY_PATH"] = os.pathsep.join( + [os.environ["LD_LIBRARY_PATH"], os.path.normpath(FLAGS.product_dir)]) + else: + os.environ["LD_LIBRARY_PATH"] = os.path.normpath(FLAGS.product_dir) + sys.exit(main(remaining_argv)) diff --git a/o3d/tests/selenium/selenium_constants.py b/o3d/tests/selenium/selenium_constants.py index 7b59b44..936772c 100644 --- a/o3d/tests/selenium/selenium_constants.py +++ b/o3d/tests/selenium/selenium_constants.py @@ -36,10 +36,13 @@ Variables that are shared across all the selenium scripts. import os -import platform +import sys + +script_dir = os.path.normpath(os.path.dirname(os.path.abspath(__file__))) +o3d_dir = os.path.dirname(os.path.dirname(script_dir)) # Default path where screenshots will be stored. -DEFAULT_SCREENSHOT_PATH = os.path.join("..", +DEFAULT_SCREENSHOT_PATH = os.path.join(o3d_dir, "tests", "selenium", "screenshots") @@ -47,14 +50,14 @@ DEFAULT_SCREENSHOT_PATH = os.path.join("..", # Path where reference screenshots will be stored. # Unfortunately we need separate reference images for certain platforms # for certain tests. -if platform.system() == "Darwin": +if sys.platform == "darwin": PLATFORM_SCREENSHOT_DIR = "reference-mac" -elif platform.system() == "Linux": +elif sys.platform[:5] == "linux": PLATFORM_SCREENSHOT_DIR = "reference-linux" -elif platform.system() == "Microsoft" or platform.system() == "Windows": +elif sys.platform == "win32" or sys.platform == "cygwin": PLATFORM_SCREENSHOT_DIR = "reference-win" else: - raise Exception, 'Platform %s not supported' % platform.system() + raise Exception, 'Platform %s not supported' % sys.platform |