def _ArchiveGoodBuild(platform, commit_position): """Archive chromedriver binary if the build is green.""" assert platform != 'android' util.MarkBuildStepStart('archive build') server_name = 'chromedriver' if util.IsWindows(): server_name += '.exe' zip_path = util.Zip(os.path.join(chrome_paths.GetBuildDir([server_name]), server_name)) build_name = 'chromedriver_%s_%s.%s.zip' % ( platform, _GetVersion(), commit_position) build_url = '%s/%s' % (GS_CONTINUOUS_URL, build_name) if slave_utils.GSUtilCopy(zip_path, build_url): util.MarkBuildStepError() if util.IsWindows(): zip_path = util.Zip(os.path.join( chrome_paths.GetBuildDir([server_name + '.pdb']), server_name + '.pdb')) pdb_name = 'chromedriver_%s_pdb_%s.%s.zip' % ( platform, _GetVersion(), commit_position) pdb_url = '%s/%s' % (GS_CONTINUOUS_URL, pdb_name) if slave_utils.GSUtilCopy(zip_path, pdb_url): util.MarkBuildStepError() (latest_fd, latest_file) = tempfile.mkstemp() os.write(latest_fd, build_name) os.close(latest_fd) latest_url = '%s/latest_%s' % (GS_CONTINUOUS_URL, platform) if slave_utils.GSUtilCopy(latest_file, latest_url, mimetype='text/plain'): util.MarkBuildStepError() os.remove(latest_file)
def GetChromePathFromPackage(): if util.IsWindows(): return 'chrome.exe' elif util.IsMac(): return 'Chromium.app/Contents/MacOS/Chromium' elif util.IsLinux(): return 'chrome'
def GetZipName(revision): if util.IsWindows(): return revision + '/chrome-win32.zip' elif util.IsMac(): return revision + '/chrome-mac.zip' elif util.IsLinux(): return revision + '/chrome-linux.zip'
def GetDirName(revision): if util.IsWindows(): return 'chrome-win' if int(revision) > 591478 else 'chrome-win32' elif util.IsMac(): return 'chrome-mac' elif util.IsLinux(): return 'chrome-linux'
def GetZipName(): if util.IsWindows(): return 'chrome-win32' elif util.IsMac(): return 'chrome-mac' elif util.IsLinux(): return 'chrome-linux'
def MaybeRelease(revision): # Version is embedded as: const char kChromeDriverVersion[] = "0.1"; # Minimum supported Chrome version is embedded as: # const int kMinimumSupportedChromeVersion[] = {27, 0, 1453, 0}; with open(os.path.join(_THIS_DIR, 'chrome', 'version.cc'), 'r') as f: lines = f.readlines() version_line = filter(lambda x: 'kChromeDriverVersion' in x, lines) chrome_min_version_line = filter( lambda x: 'kMinimumSupportedChromeVersion' in x, lines) version = version_line[0].split('"')[1] chrome_min_version = chrome_min_version_line[0].split('{')[1].split(',')[0] with open(os.path.join(chrome_paths.GetSrc(), 'chrome', 'VERSION'), 'r') as f: chrome_max_version = f.readlines()[0].split('=')[1] bitness = '32' if util.IsLinux() and platform.architecture()[0] == '64bit': bitness = '64' zip_name = 'chromedriver_%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 util.MarkBuildStepStart('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', 'ChromeDriver server for %s%s (v%s.%s.dyu) supports Chrome v%s-%s' % ( util.GetPlatformName(), bitness, version, revision, chrome_min_version, chrome_max_version), '--project', 'chromedriver', '--user', '*****@*****.**', zip_path ] with open(os.devnull, 'wb') as no_output: if subprocess.Popen(cmd, stdout=no_output, stderr=no_output).wait(): util.MarkBuildStepError()
def _RunTest(java_tests_src_dir, jvm_args, sys_props, tests_report_file): """Runs a single JUnit test suite. Args: java_tests_src_dir: the directory to run the tests in. sys_props: Java system properties to set when running the tests. jvm_args: Java VM command line args to use. """ classpath = [] for name in glob.glob(java_tests_src_dir + "/jar/*.jar"): classpath.append(name) if util.IsWindows(): separator = ';' else: separator = ':' code = util.RunCommand( ['java'] + ['-D%s' % sys_prop for sys_prop in sys_props] + ['-D%s' % jvm_arg for jvm_arg in jvm_args] + [ '-cp', separator.join(classpath), 'org.junit.runner.JUnitCore', 'org.openqa.selenium.chrome.ChromeDriverTests' ], java_tests_src_dir, tests_report_file) if code != 0: print('FAILED to run java tests of ChromeDriverTests')
def GetZipName(revision): if util.IsWindows(): return revision + ( '/chrome-win.zip' if int(revision) > 591478 else '/chrome-win32.zip') elif util.IsMac(): return revision + '/chrome-mac.zip' elif util.IsLinux(): return revision + '/chrome-linux.zip'
def _GetDownloadPlatform(): """Returns the name for this platform on the archive site.""" if util.IsWindows(): return 'win32_rel' elif util.IsMac(): return 'mac_rel' elif util.IsLinux(): return 'linux_rel'
def _GetDownloadPlatform(): """Returns the name for this platform on the archive site.""" if util.IsWindows(): return 'Win' elif util.IsMac(): return 'Mac' elif util.IsLinux(): return 'Linux_x64'
def __init__(self, server_url): self._server_url = server_url parsed_url = urlparse(server_url) timeout = 10 # see https://crbug.com/1045241: short timeout seems to introduce flakiness if util.IsMac() or util.IsWindows(): timeout = 30 self._http_client = httplib.HTTPConnection( parsed_url.hostname, parsed_url.port, timeout=timeout)
def GetZipName(revision): if util.IsWindows(): return revision + '/chrome-win32.zip' elif util.IsMac(): return revision + '/chrome-mac.zip' elif util.IsLinux(): if util.Is64Bit(): return revision + '/chrome-linux.zip' else: return 'full-build-linux_' + revision + '.zip'
def GetDirName(): if util.IsWindows(): return 'chrome-win32' elif util.IsMac(): return 'chrome-mac' elif util.IsLinux(): if util.Is64Bit(): return 'chrome-linux' else: return 'full-build-linux'
def GetDirName(): if util.IsWindows(): return 'chrome-win32' elif util.IsMac(): return 'chrome-mac' elif util.IsLinux(): if platform.architecture()[0] == '64bit': return 'chrome-linux' else: return 'full-build-linux'
def GetZipName(revision): if util.IsWindows(): return revision + '/chrome-win32.zip' elif util.IsMac(): return revision + '/chrome-mac.zip' elif util.IsLinux(): if platform.architecture()[0] == '64bit': return revision + '/chrome-linux.zip' else: return 'full-build-linux_' + revision + '.zip'
def UninstallO3DPlugin(): """Uninstalls O3D. Returns: True, if O3D is no longer installed.""" if util.IsWindows(): installer_path = os.path.join(const.PRODUCT_DIR_PATH, 'o3d.msi') os.system('msiexec.exe /x "%s" /q' % installer_path) # Forcibly remove plugins. for path in const.INSTALL_PATHS: if os.path.exists(path): if util.IsWindows(): os.remove(path) else: os.system('echo g00gl3 | sudo -S rm -rf "%s"' % path) return not DoesAnO3DPluginExist()
def RunTest(browser): """Runs tests on |browser|. Args: browser: the browser to test. Returns: True on success. """ if util.IsWindows(): if not run_util.EnsureWindowsScreenResolution( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP): logging.warn('Could not detect/change screen resolution.') # Clear all screenshots. logging.info('** Deleting previous screenshots.') if os.path.exists(SCREENSHOTS_PATH): shutil.rmtree(SCREENSHOTS_PATH) os.makedirs(SCREENSHOTS_PATH) logging.info('** Running selenium tests...') # -u for unbuffered output. # Use Python2.4 for two reasons. First, this is more or less the standard. # Second, if we use Python2.6 or later, we must manually shutdown the # httpserver, or the next run will overlap ports, which causes # some strange problems/exceptions. args = [const.PYTHON, '-u', SELENIUM_TEST_RUNNER_PATH] browser_parts = browser.split(' ', 1) args.append('--browser=' + browser_parts[0]) if len(browser_parts) > 1: args.append('--browserpath=' + browser_parts[1]) args.append('--servertimeout=80') args.append('--product_dir=' + const.PRODUCT_DIR_PATH) args.append('--verbose=0') args.append('--screenshots') args.append('--screencompare=' + IMAGE_DIFF_PATH) args.append('--screenshotsdir=' + SCREENSHOTS_PATH) args.append('--referencedir=' + O3D_REFERENCE_IMAGES_PATH) args.append('--selenium_server=' + SELENIUM_JAR_PATH) args.append('--testprefix=Test') args.append('--testsuffixes=small,medium,large') runner = TestRunningThread(args) runner.start() timeout_time = time.time() + TEST_TIMEOUT_SECS while not runner.HasFinished(): if time.time() > timeout_time: break time.sleep(5) return runner.GetReturnCode()
def _GetDownloadPlatform(): """Returns the name for this platform on the archive site.""" if util.IsWindows(): return 'Win' elif util.IsMac(): return 'Mac' elif util.IsLinux(): if util.Is64Bit(): return 'Linux_x64' else: return 'Linux Builder (dbg)(32)'
def _GetDownloadPlatform(): """Returns the name for this platform on the archive site.""" if util.IsWindows(): return 'Win' elif util.IsMac(): return 'Mac' elif util.IsLinux(): if platform.architecture()[0] == '64bit': return 'Linux_x64' else: return 'Linux'
def _GetDownloadPlatform(legacy=False): """Returns the name for this platform on the archive site. Args: legacy: When True, return name used for builds before revision 579575. TODO([email protected]): Remove when we stop supporting m69. """ if legacy: if util.IsWindows(): return 'Win' elif util.IsMac(): return 'Mac' elif util.IsLinux(): return 'Linux_x64' if util.IsWindows(): return 'win32_rel' elif util.IsMac(): return 'mac_rel' elif util.IsLinux(): return 'linux_rel'
def _KillChromes(): chrome_map = { 'win': 'chrome.exe', 'mac': 'Chromium', 'linux': 'chrome', } if util.IsWindows(): cmd = ['taskkill', '/F', '/IM'] else: cmd = ['killall', '-9'] cmd.append(chrome_map[util.GetPlatformName()]) util.RunCommand(cmd)
def InstallO3DPlugin(): """Installs O3D plugin.""" logging.info('Installing plugin...') if util.IsWindows(): installer_path = os.path.join(const.PRODUCT_DIR_PATH, 'o3d.msi') if not os.path.exists(installer_path): logging.error('Installer path not found, %s' % installer_path) return False install_command = 'msiexec.exe /i "%s"' % installer_path if util.RunStr(install_command) != 0: return False elif util.IsMac(): dmg_path = os.path.join(const.PRODUCT_DIR_PATH, 'o3d.dmg') mnt = util.MountDiskImage(dmg_path) if mnt is None: return False (device, volumes_path) = mnt installer_path = os.path.join(volumes_path, 'O3D.mpkg') if not os.path.exists(installer_path): logging.error('Installer path not found, %s' % installer_path) util.UnmountDiskImage(device) return False admin_password = '******' install_command = ('echo %s | sudo -S /usr/sbin/installer -pkg ' '"%s" -target /' % (admin_password, installer_path)) ret_code = util.RunStr(install_command) util.UnmountDiskImage(device) if ret_code != 0: return False else: plugin_path = os.path.join(const.PRODUCT_DIR_PATH, 'libnpo3dautoplugin.so') plugin_dst_dir = os.path.expanduser('~/.mozilla/plugins') try: os.makedirs(plugin_dst_dir) except os.error: pass plugin_dst = os.path.join(plugin_dst_dir, 'libnpo3dautoplugin.so') shutil.copyfile(plugin_path, plugin_dst) return True return True
def _ArchiveGoodBuild(platform, revision): assert platform != 'android' util.MarkBuildStepStart('archive build') server_name = 'chromedriver' if util.IsWindows(): server_name += '.exe' zip_path = util.Zip(os.path.join(chrome_paths.GetBuildDir([server_name]), server_name)) build_url = '%s/chromedriver_%s_%s.%s.zip' % ( GS_CONTINUOUS_URL, platform, _GetVersion(), revision) if slave_utils.GSUtilCopy(zip_path, build_url): util.MarkBuildStepError()
def HasFinished(self): # The main thread must poll the test thread because it is possible # for test_process.readline() to hang. This can happen when a debug # window opens from a crashing program. This way, we can know when # our process has exited, and then try to kill all the windows. if not self.has_started_event.isSet(): # The tests cannot have finished if they have not even started. return False self.test_process.poll() code = self.test_process.returncode if code is not None and util.IsWindows(): # Wait for the test runner to exit safely, if it is able. time.sleep(5) if not self.finished_event.isSet(): # Something is preventing proper exiting of test runner. # Try to kill all the debug windows. logging.info( 'Trying to clean up after the test. Ignore errors here.') os.system('TASKKILL /F /IM dwwin.exe') os.system('TASKKILL /F /IM iedw.exe') # Windows Error Reporting (on Vista) os.system('TASKKILL /F /IM WerFault.exe') # Browsers. os.system('TASKKILL /F /IM chrome.exe') os.system('TASKKILL /F /IM iexplore.exe') os.system('TASKKILL /F /IM firefox.exe') # Wait and see if the test is allowed to finish now. time.sleep(5) if not self.finished_event.isSet(): logging.error( 'Could not kill all the extra processes created by the' + 'test run.') else: logging.info('Test process exited succesfully.') return code is not None
def main(): parser = optparse.OptionParser() parser.add_option( '', '--android-packages', help='Comma separated list of application package names, ' '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() exe_postfix = '' if util.IsWindows(): exe_postfix = '.exe' cpp_tests_name = 'chromedriver_tests' + exe_postfix server_name = 'chromedriver' + exe_postfix required_build_outputs = [server_name] if not options.android_packages: required_build_outputs += [cpp_tests_name] try: build_dir = chrome_paths.GetBuildDir(required_build_outputs) except RuntimeError: util.MarkBuildStepStart('check required binaries') traceback.print_exc() util.MarkBuildStepError() constants.SetBuildType(os.path.basename(build_dir)) print 'Using build outputs from', build_dir chromedriver = os.path.join(build_dir, server_name) platform_name = util.GetPlatformName() if util.IsLinux() and util.Is64Bit(): platform_name += '64' ref_chromedriver = os.path.join( chrome_paths.GetSrc(), 'chrome', 'test', 'chromedriver', 'third_party', 'java_tests', 'reference_builds', 'chromedriver_%s%s' % (platform_name, exe_postfix)) if options.android_packages: os.environ['PATH'] += os.pathsep + os.path.join( _THIS_DIR, os.pardir, 'chrome') code = 0 for package in options.android_packages.split(','): code1 = RunPythonTests(chromedriver, ref_chromedriver, chrome_version_name=package, android_package=package) code2 = RunJavaTests(chromedriver, chrome_version_name=package, android_package=package, verbose=True) code = code or code1 or code2 return code else: versions = {'HEAD': archive.GetLatestRevision()} if util.IsLinux() and not util.Is64Bit(): # Linux32 builds need to be special-cased, because 1) they are keyed by # git hash rather than commit position, and 2) come from a different # download site (so we can't just convert the commit position to a hash). versions['55'] = 'e9bc4e0245c9a1e570ed2cf8e12152b9122275f2' versions['54'] = '13d140acdaa710770f42790044825b49f99e466c' versions['53'] = 'ac799c2fd50b8fb62b7a8186ff78b025de5b8718' # TODO(samuong): speculative fix for crbug.com/611886 os.environ['CHROME_DEVEL_SANDBOX'] = '/opt/chromium/chrome_sandbox' else: versions['55'] = '423791' versions['54'] = '414545' versions['53'] = '403392' code = 0 for version, revision in versions.iteritems(): if options.chrome_version and version != options.chrome_version: continue download_site = archive.GetDownloadSite() version_name = version if version_name == 'HEAD': version_name = revision temp_dir, chrome_path = DownloadChrome(version_name, revision, download_site) if not chrome_path: code = 1 continue code1 = RunPythonTests(chromedriver, ref_chromedriver, chrome=chrome_path, chrome_version=version, chrome_version_name='v%s' % version_name) code2 = RunJavaTests(chromedriver, chrome=chrome_path, chrome_version=version, chrome_version_name='v%s' % version_name) code = code or code1 or code2 _KillChromes() shutil.rmtree(temp_dir) cpp_tests = os.path.join(build_dir, cpp_tests_name) return RunCppTests(cpp_tests) or code
def _Run(java_tests_src_dir, test_filter, ready_to_run_tests, chromedriver_path, chrome_path, log_path, android_package_key, 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. readyToRunTests: tests that need to run regardless of @NotYetImplemented annotation chromedriver_path: path to ChromeDriver exe. chrome_path: path to Chrome exe. log_path: path to server log. android_package_key: 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. """ sys_props = [ 'selenium.browser=chrome', 'webdriver.chrome.driver=' + os.path.abspath(chromedriver_path) ] if chrome_path: if util.IsLinux() and android_package_key is None: # Workaround for crbug.com/611886 and # https://bugs.chromium.org/p/chromedriver/issues/detail?id=1695 chrome_wrapper_path = os.path.join(java_tests_src_dir, 'chrome-wrapper-no-sandbox') with open(chrome_wrapper_path, 'w') as f: f.write('#!/bin/sh\n') f.write('exec "%s" --no-sandbox --disable-gpu "$@"\n' % os.path.abspath(chrome_path)) st = os.stat(chrome_wrapper_path) os.chmod(chrome_wrapper_path, st.st_mode | stat.S_IEXEC) elif util.IsMac(): # Use srgb color profile, otherwise the default color profile on Mac # causes some color adjustments, so screenshots have unexpected colors. chrome_wrapper_path = os.path.join(java_tests_src_dir, 'chrome-wrapper') with open(chrome_wrapper_path, 'w') as f: f.write('#!/bin/sh\n') f.write('exec "%s" --force-color-profile=srgb "$@"\n' % os.path.abspath(chrome_path)) st = os.stat(chrome_wrapper_path) os.chmod(chrome_wrapper_path, st.st_mode | stat.S_IEXEC) else: chrome_wrapper_path = os.path.abspath(chrome_path) sys_props += ['webdriver.chrome.binary=' + chrome_wrapper_path] if log_path: sys_props += ['webdriver.chrome.logfile=' + log_path] if android_package_key: android_package = constants.PACKAGE_INFO[android_package_key].package sys_props += ['webdriver.chrome.android_package=' + android_package] if android_package_key == 'chromedriver_webview_shell': android_activity = constants.PACKAGE_INFO[ android_package_key].activity android_process = '%s:main' % android_package sys_props += [ 'webdriver.chrome.android_activity=' + android_activity ] sys_props += [ 'webdriver.chrome.android_process=' + android_process ] if test_filter: # Test jar actually takes a regex. Convert from glob. test_filter = test_filter.replace('*', '.*') sys_props += ['filter=' + test_filter] if ready_to_run_tests: sys_props += ['readyToRun=' + ready_to_run_tests] jvm_args = [] if debug: transport = 'dt_socket' if util.IsWindows(): transport = 'dt_shmem' jvm_args += [ '-agentlib:jdwp=transport=%s,server=y,suspend=y,' 'address=33081' % transport ] return _RunAntTest(java_tests_src_dir, jvm_args, verbose, sys_props)
def _Run(java_tests_src_dir, test_filter, chromedriver_path, chrome_path, log_path, android_package_key, 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. log_path: path to server log. android_package_key: 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() 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: sys_props += [ 'webdriver.chrome.binary=' + os.path.abspath(chrome_path) ] if log_path: sys_props += ['webdriver.chrome.logfile=' + log_path] if android_package_key: android_package = constants.PACKAGE_INFO[android_package_key].package sys_props += ['webdriver.chrome.android_package=' + android_package] if android_package_key == 'chromedriver_webview_shell': android_activity = constants.PACKAGE_INFO[ android_package_key].activity android_process = '%s:main' % android_package sys_props += [ 'webdriver.chrome.android_activity=' + android_activity ] sys_props += [ 'webdriver.chrome.android_process=' + android_process ] 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: transport = 'dt_socket' if util.IsWindows(): transport = 'dt_shmem' jvm_args += [ '-agentlib:jdwp=transport=%s,server=y,suspend=y,' 'address=33081' % transport ] # 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 _RunAntTest(test_dir, test_class, class_path, sys_props, jvm_args, verbose): """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, colon delimited sys_props: Java system properties to set when running the tests. jvm_args: Java VM command line args to use. verbose: whether the output should be verbose. Returns: A list of |TestResult|s. """ def _CreateBuildConfig(test_name, results_file, class_path, junit_props, sys_props, jvm_args): def _SystemPropToXml(prop): key, value = prop.split('=') return '<sysproperty key="%s" value="%s"/>' % (key, value) def _JvmArgToXml(arg): return '<jvmarg value="%s"/>' % arg return '\n'.join([ '<project>', ' <target name="test">', ' <junit %s>' % ' '.join(junit_props), ' <formatter type="xml"/>', ' <classpath>', ' <pathelement path="%s"/>' % class_path, ' </classpath>', ' ' + '\n '.join(map(_SystemPropToXml, sys_props)), ' ' + '\n '.join(map(_JvmArgToXml, jvm_args)), ' <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 error_nodes: failure = error_nodes[0].childNodes[0].nodeValue elif failure_nodes: failure = failure_nodes[0].childNodes[0].nodeValue tests += [TestResult(name, time, failure)] return tests junit_props = [ 'printsummary="yes"', 'fork="yes"', 'haltonfailure="no"', 'haltonerror="no"' ] if verbose: junit_props += ['showoutput="yes"'] ant_file = open(os.path.join(test_dir, 'build.xml'), 'w') ant_file.write( _CreateBuildConfig(test_class, 'results', class_path, junit_props, sys_props, jvm_args)) ant_file.close() if util.IsWindows(): ant_name = 'ant.bat' else: ant_name = 'ant' code = util.RunCommand([ant_name, 'test'], cwd=test_dir) if code != 0: print 'FAILED to run java tests of %s through ant' % test_class return return _ProcessResults(os.path.join(test_dir, 'results.xml'))
def main(): parser = optparse.OptionParser() parser.add_option( '', '--android-packages', help='Comma separated list of application package names, ' '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() exe_postfix = '' if util.IsWindows(): exe_postfix = '.exe' cpp_tests_name = 'chromedriver_tests' + exe_postfix server_name = 'chromedriver' + exe_postfix required_build_outputs = [server_name] if not options.android_packages: required_build_outputs += [cpp_tests_name] try: build_dir = chrome_paths.GetBuildDir(required_build_outputs) except RuntimeError: util.MarkBuildStepStart('check required binaries') traceback.print_exc() util.MarkBuildStepError() constants.SetBuildType(os.path.basename(build_dir)) print 'Using build outputs from', build_dir chromedriver = os.path.join(build_dir, server_name) platform_name = util.GetPlatformName() if util.IsLinux() and util.Is64Bit(): platform_name += '64' ref_chromedriver = os.path.join( chrome_paths.GetSrc(), 'chrome', 'test', 'chromedriver', 'third_party', 'java_tests', 'reference_builds', 'chromedriver_%s%s' % (platform_name, exe_postfix)) if options.android_packages: os.environ['PATH'] += os.pathsep + os.path.join( _THIS_DIR, os.pardir, 'chrome') code = 0 for package in options.android_packages.split(','): code1 = RunPythonTests(chromedriver, ref_chromedriver, chrome_version_name=package, android_package=package) code2 = RunJavaTests(chromedriver, chrome_version_name=package, android_package=package, verbose=True) code = code or code1 or code2 return code else: versions = {'HEAD': archive.GetLatestRevision()} if util.IsLinux() and not util.Is64Bit(): # Linux32 builds need to be special-cased, because 1) they are keyed by # git hash rather than commit position, and 2) come from a different # download site (so we can't just convert the commit position to a hash). versions['63'] = 'adb61db19020ed8ecee5e91b1a0ea4c924ae2988' versions['62'] = '17030e3a08cfbb6e591991f7dbf0eb703454b365' versions['61'] = '77132a2bc78e8dc9ce411e8166bfd009f6476f6f' # TODO(samuong): speculative fix for crbug.com/611886 os.environ['CHROME_DEVEL_SANDBOX'] = '/opt/chromium/chrome_sandbox' # Linux64 build numbers elif util.IsLinux(): versions['65'] = '530372' versions['64'] = '520842' versions['63'] = '508578' # Mac build numbers elif util.IsMac(): versions['65'] = '530368' versions['64'] = '520840' versions['63'] = '508578' # Windows build numbers elif util.IsWindows(): versions['65'] = '530366' versions['64'] = '520840' versions['63'] = '508578' code = 0 for version, revision in versions.iteritems(): if options.chrome_version and version != options.chrome_version: continue download_site = archive.GetDownloadSite() version_name = version if version_name == 'HEAD': version_name = revision temp_dir, chrome_path = DownloadChrome(version_name, revision, download_site) if not chrome_path: code = 1 continue code1 = RunPythonTests(chromedriver, ref_chromedriver, chrome=chrome_path, chrome_version=version, chrome_version_name='v%s' % version_name) code2 = RunJavaTests(chromedriver, chrome=chrome_path, chrome_version=version, chrome_version_name='v%s' % version_name) code = code or code1 or code2 _KillChromes() shutil.rmtree(temp_dir) cpp_tests = os.path.join(build_dir, cpp_tests_name) return RunCppTests(cpp_tests) or code
def main(): parser = optparse.OptionParser() parser.add_option( '', '--android-packages', help='Comma separated list of application package names, ' '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() exe_postfix = '' if util.IsWindows(): exe_postfix = '.exe' cpp_tests_name = 'chromedriver_tests' + exe_postfix server_name = 'chromedriver' + exe_postfix required_build_outputs = [server_name] if not options.android_packages: required_build_outputs += [cpp_tests_name] try: build_dir = chrome_paths.GetBuildDir(required_build_outputs) except RuntimeError: util.MarkBuildStepStart('check required binaries') traceback.print_exc() util.MarkBuildStepError() constants.SetBuildType(os.path.basename(build_dir)) print 'Using build outputs from', build_dir chromedriver = os.path.join(build_dir, server_name) platform_name = util.GetPlatformName() if util.IsLinux() and util.Is64Bit(): platform_name += '64' ref_chromedriver = os.path.join( chrome_paths.GetSrc(), 'chrome', 'test', 'chromedriver', 'third_party', 'java_tests', 'reference_builds', 'chromedriver_%s%s' % (platform_name, exe_postfix)) if options.android_packages: os.environ['PATH'] += os.pathsep + os.path.join( _THIS_DIR, os.pardir, 'chrome') code = 0 for package in options.android_packages.split(','): code1 = RunPythonTests(chromedriver, ref_chromedriver, chrome_version_name=package, android_package=package) code2 = RunJavaTests(chromedriver, chrome_version_name=package, android_package=package, verbose=True) code = code or code1 or code2 return code else: versions = {'HEAD': archive.GetLatestRevision()} if util.IsLinux() and not util.Is64Bit(): # Linux32 builds need to be special-cased, because 1) they are keyed by # git hash rather than commit position, and 2) come from a different # download site (so we can't just convert the commit position to a hash). versions['51'] = '5a161bb6fe3d6bfbe2dafc0a7dd5831478f34277' versions['50'] = '4acbec91b57f31a501264906aded632cc64c9300' versions['49'] = '7acdedefe3ddcb27b3fc826027f519bdb5d04d7e' else: versions['51'] = '386266' versions['50'] = '378110' versions['49'] = '369932' code = 0 for version, revision in versions.iteritems(): if options.chrome_version and version != options.chrome_version: continue download_site = archive.GetDownloadSite() version_name = version if version_name == 'HEAD': version_name = revision temp_dir, chrome_path = DownloadChrome(version_name, revision, download_site) if not chrome_path: code = 1 continue code1 = RunPythonTests(chromedriver, ref_chromedriver, chrome=chrome_path, chrome_version=version, chrome_version_name='v%s' % version_name) code2 = RunJavaTests(chromedriver, chrome=chrome_path, chrome_version=version, chrome_version_name='v%s' % version_name) code = code or code1 or code2 _KillChromes() shutil.rmtree(temp_dir) cpp_tests = os.path.join(build_dir, cpp_tests_name) return RunCppTests(cpp_tests) or code