def _Run(java_tests_src_dir, test_filter, chromedriver_path, chrome_path, android_package, verbose, debug): """Run the WebDriver Java tests and return the test results. Args: java_tests_src_dir: the java test source code directory. test_filter: the filter to use when choosing tests to run. Format is same as Google C++ Test format. chromedriver_path: path to ChromeDriver exe. chrome_path: path to Chrome exe. android_package: name of Chrome's Android package. verbose: whether the output should be verbose. debug: whether the tests should wait until attached by a debugger. Returns: A list of |TestResult|s. """ test_dir = util.MakeTempDir() + '1' keystore_path = ('java', 'client', 'test', 'keystore') required_dirs = [keystore_path[:-1], ('javascript',), ('third_party', 'closure', 'goog'), ('third_party', 'js')] for required_dir in required_dirs: os.makedirs(os.path.join(test_dir, *required_dir)) test_jar = 'test-standalone.jar' class_path = test_jar shutil.copyfile(os.path.join(java_tests_src_dir, 'keystore'), os.path.join(test_dir, *keystore_path)) util.Unzip(os.path.join(java_tests_src_dir, 'common.zip'), test_dir) 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=' + os.path.abspath(chromedriver_path)] if chrome_path is not None: sys_props += ['webdriver.chrome.binary=' + os.path.abspath(chrome_path)] if android_package is not None: sys_props += ['webdriver.chrome.android_package=' + android_package] if test_filter: # Test jar actually takes a regex. Convert from glob. test_filter = test_filter.replace('*', '.*') sys_props += ['filter=' + test_filter] jvm_args = [] if debug: jvm_args += ['-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,' 'address=33081'] # Unpack the sources into the test directory and add to the class path # for ease of debugging, particularly with jdb. util.Unzip(os.path.join(java_tests_src_dir, 'test-nodeps-srcs.jar'), test_dir) class_path += ':' + test_dir return _RunAntTest( test_dir, 'org.openqa.selenium.chrome.ChromeDriverTests', class_path, sys_props, jvm_args, verbose)
def MaybeRelease(revision): # Version is embedded as: const char kChromeDriverVersion[] = "0.1"; with open(os.path.join(_THIS_DIR, 'chrome', 'version.cc'), 'r') as f: version_line = filter(lambda x: 'kChromeDriverVersion' in x, f.readlines()) version = version_line[0].split('"')[1] bitness = '32' if util.IsLinux(): bitness = '64' zip_name = 'chromedriver2_%s%s_%s.zip' % ( util.GetPlatformName(), bitness, version) site = 'https://code.google.com/p/chromedriver/downloads/list' s = urllib2.urlopen(site) downloads = s.read() s.close() if zip_name in downloads: return 0 print '@@@BUILD_STEP releasing %s@@@' % zip_name if util.IsWindows(): server_orig_name = 'chromedriver2_server.exe' server_name = 'chromedriver.exe' else: server_orig_name = 'chromedriver2_server' server_name = 'chromedriver' server = os.path.join(chrome_paths.GetBuildDir([server_orig_name]), server_orig_name) print 'Zipping ChromeDriver server', server temp_dir = util.MakeTempDir() zip_path = os.path.join(temp_dir, zip_name) f = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) f.write(server, server_name) if util.IsLinux() or util.IsMac(): adb_commands = os.path.join(_THIS_DIR, 'chrome', 'adb_commands.py') f.write(adb_commands, 'adb_commands.py') f.close() cmd = [ sys.executable, os.path.join(_THIS_DIR, 'third_party', 'googlecode', 'googlecode_upload.py'), '--summary', 'version of ChromeDriver2 r%s' % revision, '--project', 'chromedriver', '--user', '*****@*****.**', '--label', 'Release', zip_path ] with open(os.devnull, 'wb') as no_output: if subprocess.Popen(cmd, stdout=no_output, stderr=no_output).wait(): print '@@@STEP_FAILURE@@@'
def Run(src_dir, test_filter, chromedriver_path, chrome_path): """Run the WebDriver Java tests and return the test results. Args: 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: A list of |TestResult|s. """ 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: 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: sys_props += ['method=' + parts[1]] if len(parts[0]) > 0: sys_props += ['only_run=' + parts[0]] return _RunAntTest(test_dir, 'org.openqa.selenium.chrome.ChromeDriverTests', test_jar, sys_props)
def MaybeRelease(revision): # Version is embedded as: const char kChromeDriverVersion[] = "0.1"; with open(os.path.join(_THIS_DIR, 'version.cc'), 'r') as f: version_line = filter(lambda x: 'kChromeDriverVersion' in x, f.readlines()) version = version_line[0].split('"')[1] # This assumes the bitness of python is the same as the built ChromeDriver. bitness = '32' if sys.maxint > 2**32: bitness = '64' zip_name = 'experimental_chromedriver2_%s%s_%s.zip' % ( util.GetPlatformName(), bitness, version) site = 'https://code.google.com/p/chromedriver/downloads/list' s = urllib2.urlopen(site) downloads = s.read() s.close() if zip_name in downloads: return 0 print '@@@BUILD_STEP releasing %s@@@' % zip_name if util.IsWindows(): server_orig_name = 'chromedriver2_server.exe' server_name = 'chromedriver.exe' else: server_orig_name = 'chromedriver2_server' server_name = 'chromedriver' server = os.path.join(chrome_paths.GetBuildDir([server_orig_name]), server_orig_name) print 'Zipping ChromeDriver server', server temp_dir = util.MakeTempDir() zip_path = os.path.join(temp_dir, zip_name) f = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) f.write(server, server_name) f.close() cmd = [ sys.executable, os.path.join(_THIS_DIR, 'third_party', 'googlecode', 'googlecode_upload.py'), '--summary', 'alpha version of ChromeDriver2 r%s' % revision, '--project', 'chromedriver', '--user', '*****@*****.**', '--label', 'Release-Alpha', zip_path ] if util.RunCommand(cmd): print '@@@STEP_FAILURE@@@'
def Download(): print '@@@BUILD_STEP Download chromedriver prebuilts@@@' temp_dir = util.MakeTempDir() zip_path = os.path.join(temp_dir, 'chromedriver2_prebuilts.zip') cmd = [ sys.executable, DOWNLOAD_SCRIPT, '--url=%s' % GS_BUCKET, '--partial-name=%s' % GS_ZIP_PREFIX, '--dst=%s' % zip_path ] if util.RunCommand(cmd): print '@@@STEP_FAILURE@@@' build_dir = chrome_paths.GetBuildDir(['host_forwarder']) print 'Unzipping prebuilts %s to %s' % (zip_path, build_dir) f = zipfile.ZipFile(zip_path, 'r') f.extractall(build_dir) f.close() # Workaround for Python bug: http://bugs.python.org/issue15795 os.chmod(os.path.join(build_dir, 'chromedriver2_server'), 0700)
def InitTestFixture(install_build, update_builds, base_url, options): """Static method for passing command options to InstallTest. We do not instantiate InstallTest. Therefore, command arguments cannot be passed to its constructor. Since InstallTest needs to use these options, and using globals is not an option, this method can be used by the Main class to pass the arguments it parses onto InstallTest. Args: install_build: A string representing the Chrome build to be used for install testing. Pass this argument only if testing fresh install scenarios. update_builds: A list that contains the Chrome builds to be used for testing update scenarios. Pass this argument only if testing upgrade scenarios. base_url: Base url of the 'official chrome builds' page. options: A list that contains options to be passed to Chrome installer. """ system = util.GetPlatformName() InstallTest._install_build = install_build InstallTest._update_builds = update_builds InstallTest._installer_options = options tempdir = util.MakeTempDir() builds = [] if InstallTest._install_build: builds.append(InstallTest._install_build) if InstallTest._update_builds: builds.extend(InstallTest._update_builds) # Remove any duplicate build numbers. builds = list(frozenset(builds)) for build in builds: url = '%s%s/%s/mini_installer.exe' % (base_url, build, system) installer_path = os.path.join(tempdir, 'mini_installer_%s.exe' % build) InstallTest._installer_paths[build] = installer_path InstallTest._Download(url, installer_path) InstallTest._chrome_driver = os.path.join(tempdir, 'chromedriver.exe') url = '%s%s/%s/%s/chromedriver.exe' % (base_url, build, system, 'chrome-win32.test') InstallTest._Download(url, InstallTest._chrome_driver)
def Archive(revision): print '@@@BUILD_STEP archive@@@' prebuilts = ['libchromedriver2.so', 'chromedriver2_server', 'chromedriver2_unittests', 'chromedriver2_tests'] build_dir = chrome_paths.GetBuildDir(prebuilts[0:1]) zip_name = '%s_r%s.zip' % (GS_ZIP_PREFIX, revision) temp_dir = util.MakeTempDir() zip_path = os.path.join(temp_dir, zip_name) print 'Zipping prebuilts %s' % zip_path f = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) for prebuilt in prebuilts: f.write(os.path.join(build_dir, prebuilt), prebuilt) f.close() cmd = [ sys.executable, UPLOAD_SCRIPT, '--source_filepath=%s' % zip_path, '--dest_gsbase=%s' % GS_BUCKET ] if util.RunCommand(cmd): print '@@@STEP_FAILURE@@@'
def Archive(revision): print '@@@BUILD_STEP archive@@@' prebuilts = ['libchromedriver2.so', 'chromedriver2_server', 'chromedriver2_unittests', 'chromedriver2_tests'] build_dir = chrome_paths.GetBuildDir(prebuilts[0:1]) zip_name = 'chromedriver2_prebuilts_r%s.zip' % revision temp_dir = util.MakeTempDir() zip_path = os.path.join(temp_dir, zip_name) print 'Zipping prebuilts %s' % zip_path f = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) for prebuilt in prebuilts: f.write(os.path.join(build_dir, prebuilt), prebuilt) f.close() gs_bucket = 'gs://chromedriver-prebuilts' cmd = [ sys.executable, '../../../scripts/slave/skia/upload_to_bucket.py', '--source_filepath=%s' % zip_path, '--dest_gsbase=%s' % gs_bucket ] if util.RunCommand(cmd): print '@@@STEP_FAILURE@@@'
def main(): parser = optparse.OptionParser() parser.add_option( '', '--filter', type='string', default=None, help='Filter for specifying what tests to run. E.g., ' + 'ElementFindingTest#testShouldReturnTitleOfPageIfSet.') options, args = parser.parse_args() print '@@@BUILD_STEP java_continuous_tests@@@' # We use the latest revision in the continuous archive instead of the # extracted build for two reasons: # 1) Builds are only archived if they have passed some set of tests. This # results in less false failures. # 2) I don't want to add chromedriver to the chromium_builder_tests target in # all.gyp, since that will probably add a minute or so to every build. revision = continuous_archive.GetLatestRevision() print '@@@STEP_TEXT@r%s@@@' % revision temp_dir = util.MakeTempDir() chrome_path = continuous_archive.DownloadChrome(revision, temp_dir) chromedriver_path = continuous_archive.DownloadChromeDriver( revision, temp_dir) PrintTestResults(java_tests.Run( src_dir=chrome_paths.GetSrc(), test_filter=options.filter, 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( src_dir=chrome_paths.GetSrc(), test_filter=options.filter, chromedriver_path=chromedriver_path, chrome_path=None))
def _Run(src_dir, java_tests_src_dir, test_filter, chromedriver_path, chrome_path): """Run the WebDriver Java tests and return the test results. Args: src_dir: the chromium source checkout directory. java_tests_src_dir: the java test source code 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: A list of |TestResult|s. """ 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' 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: sys_props += ['webdriver.chrome.binary=' + chrome_path] if test_filter != '' and test_filter != '*': classes = [] methods = [] cases = test_filter.split(',') for case in cases: parts = case.split('#') if len(parts) > 2: raise RuntimeError( 'Filter should be of form: SomeClass#testMethod') elif len(parts) == 2: methods += [parts[1]] if len(parts[0]) > 0: classes += [parts[0]] sys_props += ['only_run=' + ','.join(classes)] sys_props += ['method=' + ','.join(methods)] # Make a copy of chormedriver library, because java expects a different name. expected_chromedriver_map = { 'win': 'chromedriver.dll', 'mac': 'libchromedriver.jnilib', 'linux': 'libchromedriver.so', } expected_chromedriver = expected_chromedriver_map[util.GetPlatformName()] expected_chromedriver_path = os.path.join(test_dir, expected_chromedriver) shutil.copyfile(chromedriver_path, expected_chromedriver_path) sys_props += ['java.library.path=' + test_dir] return _RunAntTest(test_dir, 'org.openqa.selenium.chrome.ChromeDriverTests', test_jar, sys_props)
def main(): parser = optparse.OptionParser() parser.add_option( '', '--android-package', help='Application package name, if running tests on Android.') # Option 'chrome-version' is for desktop only. parser.add_option( '', '--chrome-version', help='Version of chrome, e.g., \'HEAD\', \'27\', or \'26\'.' 'Default is to run tests against all of these versions.' 'Notice: this option only applies to desktop.') options, _ = parser.parse_args() chromedriver_map = { 'win': 'chromedriver2.dll', 'mac': 'chromedriver2.so', 'linux': 'libchromedriver2.so', } chromedriver_name = chromedriver_map[util.GetPlatformName()] chrome_map = { 'win': 'chrome.exe', 'mac': 'Chromium.app/Contents/MacOS/Chromium', 'linux': 'chrome', } chrome_name = chrome_map[util.GetPlatformName()] if util.IsWindows(): cpp_tests_name = 'chromedriver2_tests.exe' server_name = 'chromedriver2_server.exe' else: cpp_tests_name = 'chromedriver2_tests' server_name = 'chromedriver2_server' required_build_outputs = [chromedriver_name] if not options.android_package: required_build_outputs += [cpp_tests_name, server_name] build_dir = chrome_paths.GetBuildDir(required_build_outputs) print 'Using build outputs from', build_dir chromedriver = os.path.join(build_dir, chromedriver_name) chromedriver_server = os.path.join(build_dir, server_name) if util.IsLinux(): # Set LD_LIBRARY_PATH to enable successful loading of shared object files, # when chromedriver2.so is not a static build. _AppendEnvironmentPath('LD_LIBRARY_PATH', os.path.join(build_dir, 'lib')) elif util.IsWindows(): # For Windows bots: add ant, java(jre) and the like to system path. _AddToolsToSystemPathForWindows() if options.android_package: os.environ['PATH'] += os.pathsep + os.path.join(_THIS_DIR, 'chrome') code1 = RunPythonTests(chromedriver, android_package=options.android_package) code2 = RunJavaTests(chromedriver_server, android_package=options.android_package) return code1 or code2 else: chrome_tip_of_tree = os.path.join(build_dir, chrome_name) cpp_tests = os.path.join(build_dir, cpp_tests_name) chrome_26 = continuous_archive.DownloadChrome( continuous_archive.CHROME_26_REVISION, util.MakeTempDir()) chrome_27 = continuous_archive.DownloadChrome( continuous_archive.CHROME_27_REVISION, util.MakeTempDir()) chrome_path_versions = [ { 'path': chrome_tip_of_tree, 'version': 'HEAD' }, { 'path': chrome_27, 'version': '27' }, { 'path': chrome_26, 'version': '26' }, ] code = 0 for chrome in chrome_path_versions: if options.chrome_version and chrome[ 'version'] != options.chrome_version: continue code1 = RunPythonTests(chromedriver, chrome=chrome['path'], chrome_version=chrome['version']) code2 = RunJavaTests(chromedriver_server, chrome=chrome['path'], chrome_version=chrome['version']) code = code or code1 or code2 return RunCppTests(cpp_tests) or code
def setUp(self): super(ThemeUpdater, self).setUp() self._user_data_dir = util.MakeTempDir()