summaryrefslogtreecommitdiffstats
path: root/chrome/test/webdriver
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/test/webdriver')
-rw-r--r--chrome/test/webdriver/test/java_tests.py178
-rwxr-xr-xchrome/test/webdriver/test/run_webdriver_java_tests.py14
2 files changed, 100 insertions, 92 deletions
diff --git a/chrome/test/webdriver/test/java_tests.py b/chrome/test/webdriver/test/java_tests.py
index 8d28b16..8be4bb8 100644
--- a/chrome/test/webdriver/test/java_tests.py
+++ b/chrome/test/webdriver/test/java_tests.py
@@ -5,6 +5,7 @@
"""Runs the WebDriver Java tests."""
import os
+import shutil
import xml.dom.minidom as minidom
import util
@@ -42,98 +43,109 @@ class TestResult(object):
return self._failure
-class _TestTarget(object):
- """A WebDriver test target."""
-
- def __init__(self, target_path, target_name, test_class):
- """Initializes a test target.
-
- Args:
- target_path: the full target name that should be passed to WebDriver's go
- script.
- target_name: the name of the target. This is equal to the 'name' field of
- the target in the 'build.desc' file.
- test_class: the name of the test class.
- """
- self._target_path = target_path
- self._target_name = target_name
- self._test_class = test_class
-
- def GetTargetPath(self):
- """Returns the full target name, e.g., //java/somepackage:test:run."""
- return self._target_path
-
- def GetResultFileName(self):
- """Returns the name of the file which will contain the test results."""
- return 'TEST-%s-%s.xml' % (self._target_name, self._test_class)
-
-
-# Contains all standard selenium tests that should pass with stable Chrome.
-CHROME_TESTS = _TestTarget(
- '//java/client/test/org/openqa/selenium/chrome:test:run',
- 'test',
- 'org.openqa.selenium.chrome.ChromeDriverTests')
-
-
-#TODO(kkania): Add target for running all ignored tests.
-
-
-def Run(test_target, test_filter, webdriver_dir, chromedriver_path,
- chrome_path):
- """Runs the WebDriver Java test target and returns the results.
+def Run(src_dir, test_filter, chromedriver_path, chrome_path):
+ """Run the WebDriver Java tests and return the test results.
Args:
- test_target: a |TestTarget| to run.
- test_filter: the Java test filter to use. Should take the form
- MyClass#testMethod.
- webdriver_dir: the path to a WebDriver source checkout.
- chromedriver_path: the path to the ChromeDriver to use.
- chrome_path: the path to the Chrome binary to use. If None, ChromeDriver
- will use the system Chrome installation.
+ src_dir: the chromium source checkout directory.
+ test_filter: the filter to use when choosing tests to run. Format is
+ ClassName#testMethod.
+ chromedriver_path: path to ChromeDriver exe.
+ chrome_path: path to Chrome exe.
Returns:
- List of |TestResult|s.
+ A list of |TestResult|s.
"""
- results_path = os.path.join(webdriver_dir, 'build', 'test_logs',
- test_target.GetResultFileName())
- if os.path.exists(results_path):
- os.remove(results_path)
- if util.IsWin():
- go_name = 'go.bat'
- else:
- go_name = 'go'
- go = os.path.join(webdriver_dir, go_name)
- command = [go, test_target.GetTargetPath()]
- command += ['haltonerror=false', 'haltonfailure=false', 'log=true']
- command += ['chromedriver=' + chromedriver_path]
+ test_dir = util.MakeTempDir()
+ keystore_path = ('java', 'client', 'test', 'keystore')
+ required_dirs = [keystore_path[:-1],
+ ('javascript',),
+ ('third_party', 'closure', 'goog')]
+ for required_dir in required_dirs:
+ os.makedirs(os.path.join(test_dir, *required_dir))
+
+ test_jar = 'test-standalone.jar'
+ java_tests_src_dir = os.path.join(
+ src_dir, 'third_party', 'webdriver', 'java_tests')
+ shutil.copyfile(os.path.join(java_tests_src_dir, 'keystore'),
+ os.path.join(test_dir, *keystore_path))
+ shutil.copytree(os.path.join(java_tests_src_dir, 'common'),
+ os.path.join(test_dir, 'common'))
+ shutil.copyfile(os.path.join(java_tests_src_dir, test_jar),
+ os.path.join(test_dir, test_jar))
+
+ sys_props = ['selenium.browser=chrome',
+ 'webdriver.chrome.driver=' + chromedriver_path]
if chrome_path is not None:
- command += ['chrome=' + chrome_path]
+ sys_props += ['webdriver.chrome.binary=' + chrome_path]
if test_filter is not None:
parts = test_filter.split('#')
if len(parts) > 2:
raise RuntimeError('Filter should be of form: SomeClass#testMethod')
elif len(parts) == 2:
- command += ['method=' + parts[1]]
+ sys_props += ['method=' + parts[1]]
if len(parts[0]) > 0:
- command += ['onlyrun=' + parts[0]]
- print "Running ", ' '.join(command)
- util.RunCommand(command, cwd=webdriver_dir)
- return _ProcessResults(results_path)
-
-
-def _ProcessResults(results_path):
- """Returns a list of |TestResult|s from the given result file."""
- doc = minidom.parse(results_path)
- tests = []
- for test in doc.getElementsByTagName('testcase'):
- name = test.getAttribute('classname') + '.' + test.getAttribute('name')
- time = test.getAttribute('time')
- failure = None
- error_nodes = test.getElementsByTagName('error')
- failure_nodes = test.getElementsByTagName('failure')
- if len(error_nodes) > 0:
- failure = error_nodes[0].childNodes[0].nodeValue
- elif len(failure_nodes) > 0:
- failure = failure_nodes[0].childNodes[0].nodeValue
- tests += [TestResult(name, time, failure)]
- return tests
+ sys_props += ['only_run=' + parts[0]]
+
+ return _RunAntTest(
+ test_dir, 'org.openqa.selenium.chrome.ChromeDriverTests',
+ test_jar, sys_props)
+
+
+def _RunAntTest(test_dir, test_class, class_path, sys_props):
+ """Runs a single Ant JUnit test suite and returns the |TestResult|s.
+
+ Args:
+ test_dir: the directory to run the tests in.
+ test_class: the name of the JUnit test suite class to run.
+ class_path: the Java class path used when running the tests.
+ sys_props: Java system properties to set when running the tests.
+ """
+
+ def _CreateBuildConfig(test_name, results_file, class_path, junit_props,
+ sys_props):
+ def _SystemPropToXml(prop):
+ key, value = prop.split('=')
+ return '<sysproperty key="%s" value="%s"/>' % (key, value)
+ return '\n'.join([
+ '<project>',
+ ' <target name="test">',
+ ' <junit %s>' % ' '.join(junit_props),
+ ' <formatter type="xml"/>',
+ ' <classpath>',
+ ' <pathelement location="%s"/>' % class_path,
+ ' </classpath>',
+ ' ' + '\n '.join(map(_SystemPropToXml, sys_props)),
+ ' <test name="%s" outfile="%s"/>' % (test_name, results_file),
+ ' </junit>',
+ ' </target>',
+ '</project>'])
+
+ def _ProcessResults(results_path):
+ doc = minidom.parse(results_path)
+ tests = []
+ for test in doc.getElementsByTagName('testcase'):
+ name = test.getAttribute('classname') + '.' + test.getAttribute('name')
+ time = test.getAttribute('time')
+ failure = None
+ error_nodes = test.getElementsByTagName('error')
+ failure_nodes = test.getElementsByTagName('failure')
+ if len(error_nodes) > 0:
+ failure = error_nodes[0].childNodes[0].nodeValue
+ elif len(failure_nodes) > 0:
+ failure = failure_nodes[0].childNodes[0].nodeValue
+ tests += [TestResult(name, time, failure)]
+ return tests
+
+ junit_props = ['printsummary="yes"',
+ 'fork="yes"',
+ 'haltonfailure="no"',
+ 'haltonerror="no"']
+
+ ant_file = open(os.path.join(test_dir, 'build.xml'), 'w')
+ ant_file.write(_CreateBuildConfig(
+ test_class, 'results', class_path, junit_props, sys_props))
+ ant_file.close()
+
+ util.RunCommand(['ant', 'test'], cwd=test_dir)
+ return _ProcessResults(os.path.join(test_dir, 'results.xml'))
diff --git a/chrome/test/webdriver/test/run_webdriver_java_tests.py b/chrome/test/webdriver/test/run_webdriver_java_tests.py
index 48d048c..c3518b7 100755
--- a/chrome/test/webdriver/test/run_webdriver_java_tests.py
+++ b/chrome/test/webdriver/test/run_webdriver_java_tests.py
@@ -17,6 +17,7 @@ import sys
import continuous_archive
import java_tests
+import test_paths
import util
@@ -24,13 +25,10 @@ def main():
parser = optparse.OptionParser()
parser.add_option(
'', '--filter', type='string', default=None,
- help='Filter for specifying what tests to run. E.g., MyClass#testMethod.')
+ help='Filter for specifying what tests to run. E.g., ' +
+ 'ElementFindingTest#testShouldReturnTitleOfPageIfSet.')
options, args = parser.parse_args()
- if 'WEBDRIVER_CHECKOUT' not in os.environ:
- raise RuntimeError('WEBDRIVER_CHECKOUT must be defined in the environment')
- webdriver_checkout = os.environ['WEBDRIVER_CHECKOUT']
-
print '@@@BUILD_STEP java_continuous_tests@@@'
# We use the latest revision in the continuous archive instead of the
# extracted build for two reasons:
@@ -47,18 +45,16 @@ def main():
revision, temp_dir)
PrintTestResults(java_tests.Run(
- test_target=java_tests.CHROME_TESTS,
+ src_dir=test_paths.SRC_PATH,
test_filter=options.filter,
- webdriver_dir=webdriver_checkout,
chromedriver_path=chromedriver_path,
chrome_path=chrome_path))
print '@@@BUILD_STEP java_stable_tests@@@'
print '@@@STEP_TEXT@chromedriver r%s@@@' % revision
PrintTestResults(java_tests.Run(
- test_target=java_tests.CHROME_TESTS,
+ src_dir=test_paths.SRC_PATH,
test_filter=options.filter,
- webdriver_dir=webdriver_checkout,
chromedriver_path=chromedriver_path,
chrome_path=None))