Пример #1
0
 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'
Пример #2
0
 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'
Пример #3
0
 def GetZipName():
     if util.IsWindows():
         return 'chrome-win32'
     elif util.IsMac():
         return 'chrome-mac'
     elif util.IsLinux():
         return 'chrome-linux'
Пример #4
0
 def GetChromedriverPath():
     if util.IsWin():
         return 'chrome-win32.test/chromedriver.exe'
     elif util.IsMac():
         return 'chrome-mac.test/chromedriver'
     elif util.IsLinux():
         return 'chrome-linux.test/chromedriver'
Пример #5
0
 def GetChromePathFromPackage():
     if util.IsWindows():
         return 'chrome.exe'
     elif util.IsMac():
         return 'Chromium.app/Contents/MacOS/Chromium'
     elif util.IsLinux():
         return 'chrome'
Пример #6
0
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'
Пример #7
0
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'
Пример #8
0
 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'
Пример #9
0
 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)
Пример #10
0
 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'
Пример #11
0
 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'
Пример #12
0
 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'
Пример #13
0
 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'
Пример #14
0
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)'
Пример #15
0
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'
Пример #16
0
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'
Пример #17
0
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
Пример #18
0
 def _FindChrome():
   possible_paths = []
   if util.IsWin():
     possible_paths += ['chrome.exe']
   elif util.IsMac():
     possible_paths += ['Chromium.app/Contents/MacOS/Chromium',
                        'Google Chrome.app/Contents/MacOS/Google Chrome']
   elif util.IsLinux():
     possible_paths += ['chrome']
   for dir in _DefaultExeLocations():
     for chrome_path in possible_paths:
       path = os.path.abspath(os.path.join(dir, chrome_path))
       if os.path.exists(path):
         return path
   return None
Пример #19
0
def _RunAntTest(java_tests_src_dir, test_filter, chromedriver_path,
                chrome_path, log_path, android_package_key, jvm_args, verbose,
                debug, 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, 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(java_tests_src_dir, jvm_args, sys_props):
        path_element = []

        for name in glob.glob(java_tests_src_dir + "/jar/*.jar"):
            path_element.append('\t<pathelement location=\"%s\" />' % name)

        build_xml = '\n'.join([
            '<project>',
            ' <property name="test.class.name" value="org.openqa.selenium.chrome.ChromeDriverTests" />',
            ' <path id="test.classpath">', '\n'.join(path_element), '</path>'
        ])

        def _SystemPropToXml(prop):
            key, value = prop.split('=')
            return '<sysproperty key="%s" value="%s"/>' % (key, value)

        def _JvmArgToXml(arg):
            return '<jvmarg value="%s"/>' % arg

        build_xml += '\n'.join([
            '  <target name="test">',
            '    <junit %s>' % ' '.join(junit_props),
            '      <formatter type="xml"/>',
            '      ' + '\n      '.join(map(_SystemPropToXml, sys_props)),
            '      ' + '\n      '.join(map(_JvmArgToXml, jvm_args)),
            '      <test name="%s" outfile="%s"/>' %
            ("org.openqa.selenium.chrome.ChromeDriverTests", "results"),
            '      <classpath refid="test.classpath" />', '    </junit>',
            '  </target>', '</project>'
        ])

        return build_xml

    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(java_tests_src_dir, 'build.xml'), 'w')
    file_contents = _CreateBuildConfig(java_tests_src_dir, jvm_args, sys_props)
    if util.IsMac():
        print file_contents
    ant_file.write(file_contents)
    ant_file.close()

    if util.IsWindows():
        ant_name = 'ant.bat'
    else:
        ant_name = 'ant'
    code = util.RunCommand([ant_name, 'test'], java_tests_src_dir)
    if code != 0:
        print 'FAILED to run java tests of ChromeDriverTests through ant'
        return
    return _ProcessResults(os.path.join(java_tests_src_dir, 'results.xml'))
Пример #20
0
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
Пример #21
0
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)
Пример #22
0

"""Defines common O3D test runner constants. This file determines paths to
other O3D components relatively, so it must be placed in the right location.

"""

import os
import sys

import util

join = os.path.join

# Make sure OS is supported.
if not util.IsWindows() and not util.IsMac() and not util.IsLinux():
  print 'Only Windows, Mac, and Linux are supported.'
  sys.exit(1)

# This path should be root/o3d/tests.
TEST_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# This path should be root/o3d.
O3D_PATH = os.path.dirname(TEST_PATH)
# This path should be root, i.e., the checkout location.
BASE_PATH = os.path.dirname(O3D_PATH)


HOME = os.path.expanduser('~')
if HOME == '~':
  print 'Cannot find user home directory.'
  sys.exit(1)
Пример #23
0
if util.IsWindows():
  _DESKTOP_OS_SPECIFIC_FILTER = [
      # https://code.google.com/p/chromedriver/issues/detail?id=214
      'ChromeDriverTest.testCloseWindow',
      # https://code.google.com/p/chromedriver/issues/detail?id=299
      'ChromeLogPathCapabilityTest.testChromeLogPath',
  ]
elif util.IsLinux():
  _DESKTOP_OS_SPECIFIC_FILTER = [
      # Xvfb doesn't support maximization.
      'ChromeDriverTest.testWindowMaximize',
      # https://code.google.com/p/chromedriver/issues/detail?id=302
      'ChromeDriverTest.testWindowPosition',
      'ChromeDriverTest.testWindowSize',
  ]
elif util.IsMac():
  _DESKTOP_OS_SPECIFIC_FILTER = [
      # https://code.google.com/p/chromedriver/issues/detail?id=304
      'ChromeDriverTest.testGoBackAndGoForward',
  ]


_DESKTOP_NEGATIVE_FILTER = {}
_DESKTOP_NEGATIVE_FILTER['HEAD'] = (
    _DESKTOP_OS_SPECIFIC_FILTER + [
        # https://code.google.com/p/chromedriver/issues/detail?id=213
        'ChromeDriverTest.testClickElementInSubFrame',
        # This test is flaky since it uses setTimeout.
        # Re-enable once crbug.com/177511 is fixed and we can remove setTimeout.
        'ChromeDriverTest.testAlert',
        # Desktop doesn't support TAP.
Пример #24
0
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()}
        # Linux64 build numbers
        if util.IsLinux():
            versions['72'] = '612434'
            versions['71'] = '599034'
            versions['70'] = '587811'

        # Mac build numbers
        elif util.IsMac():
            versions['72'] = '612451'
            versions['71'] = '599028'
            versions['70'] = '587811'

        # Windows build numbers
        elif util.IsWindows():
            versions['72'] = '612432'
            versions['71'] = '598927'
            versions['70'] = '587814'

        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,
                                 verbose=True)
            code3 = RunReplayTests(chromedriver,
                                   chrome=chrome_path,
                                   chrome_version=version,
                                   chrome_version_name='v%s' % version_name)
            code = code or code1 or code2 or code3
            _KillChromes()
            shutil.rmtree(temp_dir)
        cpp_tests = os.path.join(build_dir, cpp_tests_name)
        return RunCppTests(cpp_tests) or code
Пример #25
0
class ExtensionTest(ChromeDriverTest):

    INFOBAR_BROWSER_ACTION_EXTENSION = test_paths.TEST_DATA_PATH + \
        '/infobar_browser_action_extension'
    PAGE_ACTION_EXTENSION = test_paths.TEST_DATA_PATH + \
        '/page_action_extension'

    def testExtensionInstallAndUninstall(self):
        driver = self.GetNewDriver()
        self.assertEquals(0, len(driver.get_installed_extensions()))
        ext = driver.install_extension(self.PAGE_ACTION_EXTENSION)
        extensions = driver.get_installed_extensions()
        self.assertEquals(1, len(extensions))
        self.assertEquals(ext.id, extensions[0].id)
        ext.uninstall()
        self.assertEquals(0, len(driver.get_installed_extensions()))

    def testExtensionInfo(self):
        driver = self.GetNewDriver()
        ext = driver.install_extension(self.PAGE_ACTION_EXTENSION)
        self.assertEquals('Page action extension', ext.get_name())
        self.assertEquals('1.0', ext.get_version())
        self.assertEquals(32, len(ext.id))
        self.assertTrue(ext.is_enabled())
        ext.set_enabled(True)
        ext.set_enabled(False)
        self.assertFalse(ext.is_enabled())
        ext.set_enabled(True)
        self.assertTrue(ext.is_enabled())

    def _testExtensionView(self, driver, view_handle, extension):
        """Tests that the given view supports basic WebDriver functionality."""
        driver.switch_to_window(view_handle)
        self.assertTrue(driver.execute_script('return true'))
        checkbox = driver.find_element_by_id('checkbox')
        checkbox.click()
        self.assertTrue(checkbox.is_selected())
        textfield = driver.find_element_by_id('textfield')
        textfield.send_keys('test')
        self.assertEquals('test', textfield.get_attribute('value'))
        self.assertEquals('test', driver.title)
        self.assertTrue(driver.current_url.endswith('view_checks.html'))
        self.assertTrue('Should be in page source' in driver.page_source)
        driver.close()

        def is_view_closed(driver):
            return len(
                filter(lambda view: view['handle'] == view_handle,
                       extension._get_views())) == 0

        WebDriverWait(driver, 10).until(is_view_closed)

    # Mac extension infobars are currently broken: crbug.com/107573.
    @SkipIf(util.IsMac())
    def testInfobarView(self):
        driver = self.GetNewDriver(
            {'chrome.switches': ['enable-experimental-extension-apis']})
        ext = driver.install_extension(self.INFOBAR_BROWSER_ACTION_EXTENSION)
        driver.switch_to_window(ext.get_bg_page_handle())
        driver.set_script_timeout(10)
        driver.execute_async_script('waitForInfobar(arguments[0])')
        self._testExtensionView(driver, ext.get_infobar_handles()[0], ext)

    def testBrowserActionPopupView(self):
        driver = self.GetNewDriver(
            {'chrome.switches': ['enable-experimental-extension-apis']})
        ext = driver.install_extension(self.INFOBAR_BROWSER_ACTION_EXTENSION)
        ext.click_browser_action()
        self._testExtensionView(driver, ext.get_popup_handle(), ext)

    def testPageActionPopupView(self):
        driver = self.GetNewDriver()
        ext = driver.install_extension(self.PAGE_ACTION_EXTENSION)

        def is_page_action_visible(driver):
            return ext.is_page_action_visible()

        WebDriverWait(driver, 10).until(is_page_action_visible)
        ext.click_page_action()
        self._testExtensionView(driver, ext.get_popup_handle(), ext)
Пример #26
0
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:
    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(test_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(test_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]

  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)