示例#1
0
def setup_chrome():
    """ Initialize the Chrome browser. """
    global _chrome_version
    if sys.platform == 'win32':  # No command-line version capability.
        pattern = os.path.join(os.path.dirname(find_chrome()), '[0-9]*')
        _chrome_version = os.path.basename(sorted(glob.glob(pattern),
                                                  reverse=True)[0])
    else:
        _chrome_version = subprocess.check_output([find_chrome(), '--version'])
        _chrome_version = _chrome_version.strip().split()
        if _chrome_version[0] == 'Chromium':
            _chrome_version = _chrome_version[1]
        else:
            _chrome_version = _chrome_version[-1]
    _chrome_version = int(_chrome_version.split('.')[0])

    exe = 'chromedriver'
    path = find_executable(exe)
    if not path:
        # Download, unpack, and install chromedriver in OpenMDAO 'bin'.
        prefix = 'http://chromedriver.googlecode.com/files/'
        version = '2.2' if _chrome_version > 28 else '23.0.1240.0'
        if sys.platform == 'darwin':
            flavor = 'mac32' if _chrome_version > 28 else 'mac'
        elif sys.platform == 'win32':
            flavor = 'win32' if _chrome_version > 28 else 'win'
        elif '64bit' in platform.architecture():
            flavor = 'linux64'
        else:
            flavor = 'linux32'
        filename = '%s_%s_%s.zip' % (exe, flavor, version)
        orig_dir = os.getcwd()
        os.chdir(os.path.dirname(sys.executable))
        try:
            logging.critical('Downloading %s to %s', filename, os.getcwd())
            src = urllib2.urlopen(prefix + filename)
            with open(filename, 'wb') as dst:
                dst.write(src.read())
            src.close()
            zip = zipfile.ZipFile(filename)
            if sys.platform == 'win32':
                exe += '.exe'
            zip.extract(exe)
            zip.close()
            if sys.platform != 'win32':
                os.chmod(exe, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
            path = os.path.join(os.getcwd(), exe)
            os.remove(filename)
        finally:
            os.chdir(orig_dir)
    driver = webdriver.Chrome(executable_path=path)
    driver.implicitly_wait(15)
    TEST_CONFIG['browsers'].append(driver)
    return driver
示例#2
0
def setup_chrome():
    """ Initialize the Chrome browser. """
    global _chrome_version
    if sys.platform == 'win32':  # No command-line version capability.
        pattern = os.path.join(os.path.dirname(find_chrome()), '[0-9]*')
        _chrome_version = os.path.basename(
            sorted(glob.glob(pattern), reverse=True)[0])
    else:
        _chrome_version = subprocess.check_output([find_chrome(), '--version'])
        _chrome_version = _chrome_version.strip().split()
        if _chrome_version[0] == 'Chromium':
            _chrome_version = _chrome_version[1]
        else:
            _chrome_version = _chrome_version[-1]
    _chrome_version = int(_chrome_version.split('.')[0])

    exe = 'chromedriver'
    path = find_executable(exe)
    if not path:
        # Download, unpack, and install chromedriver into OpenMDAO 'bin'.
        if _chrome_version > 29:
            version = 2.8
        elif _chrome_version > 28:
            version = 2.6
        else:
            version = 2.3

        if sys.platform == 'darwin':
            flavor = 'mac32'
        elif sys.platform == 'win32':
            flavor = 'win32'
        elif '64bit' in platform.architecture():
            flavor = 'linux64'
        else:
            flavor = 'linux32'

        filename = '%s_%s.zip' % (exe, flavor)

        orig_dir = os.getcwd()
        os.chdir(os.path.dirname(sys.executable))

        prefix = 'http://chromedriver.storage.googleapis.com'
        url = '/'.join([prefix, str(version), filename])
        logging.critical('Downloading %s for chrome version %d to %s', url,
                         _chrome_version, os.getcwd())
        try:
            src = urllib2.urlopen(url)
            with open(filename, 'wb') as dst:
                dst.write(src.read())
            src.close()
            zip = zipfile.ZipFile(filename)
            if sys.platform == 'win32':
                exe += '.exe'
            zip.extract(exe)
            zip.close()
            if sys.platform != 'win32':
                os.chmod(exe, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
            path = os.path.join(os.getcwd(), exe)
            os.remove(filename)
        finally:
            os.chdir(orig_dir)
    driver = webdriver.Chrome(executable_path=path)
    driver.implicitly_wait(15)
    TEST_CONFIG['browsers'].append(driver)
    return driver
示例#3
0
def check_for_chrome():
    return bool(find_chrome())
示例#4
0
def check_for_chrome():
    if find_chrome() is not None:
        return True
    else:
        return False
示例#5
0
def check_for_chrome():
    return bool(find_chrome())
示例#6
0
def check_for_chrome():
    if find_chrome() is not None:
        return True
    else:
        return False