有没有办法在Test Automation Suite目录中自动更新chromedriver?

时间:2018-05-30 10:28:23

标签: java python-3.x selenium-webdriver selenium-chromedriver

我有一个使用Selenium和Python的自动化框架。为了运行Chrome浏览器,我将chrome驱动程序放在自动化框架的其中一个文件夹中。现在的问题是Chrome驱动程序在一段时间后得到了更新,我的脚本因此而开始失败,每当Google更新时,我都需要将更新的chrome驱动程序放在目录中。

我是否可以采用任何自动方式来解决此问题?

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,所以我制作了一个硒脚本来自动从chromedrivers网站下载exe文件,并获取我所有的脚本以引用pythondriver中chromedriver.exe文件的当前位置。我在调度程序中与Google更新并行运行此脚本,因此当chrome更新时,驱动程序也会更新。

随意使用/重新组装它。

-getFileProperties.py-

{
  "message": "Not Found",
  "documentation_url": "https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository"
}

-ChromeVersion.py-

# as per https://stackoverflow.com/questions/580924/python-windows-file-version-attribute

import win32api

#==============================================================================
def getFileProperties(fname):
#==============================================================================
    """
    Read all properties of the given file return them as a dictionary.
    """
    propNames = ('Comments', 'InternalName', 'ProductName',
        'CompanyName', 'LegalCopyright', 'ProductVersion',
        'FileDescription', 'LegalTrademarks', 'PrivateBuild',
        'FileVersion', 'OriginalFilename', 'SpecialBuild')

    props = {'FixedFileInfo': None, 'StringFileInfo': None, 'FileVersion': None}

    try:
        # backslash as parm returns dictionary of numeric info corresponding to VS_FIXEDFILEINFO struc
        fixedInfo = win32api.GetFileVersionInfo(fname, '\\')
        props['FixedFileInfo'] = fixedInfo
        props['FileVersion'] = "%d.%d.%d.%d" % (fixedInfo['FileVersionMS'] / 65536,
                fixedInfo['FileVersionMS'] % 65536, fixedInfo['FileVersionLS'] / 65536,
                fixedInfo['FileVersionLS'] % 65536)

        # \VarFileInfo\Translation returns list of available (language, codepage)
        # pairs that can be used to retreive string info. We are using only the first pair.
        lang, codepage = win32api.GetFileVersionInfo(fname, '\\VarFileInfo\\Translation')[0]

        # any other must be of the form \StringfileInfo\%04X%04X\parm_name, middle
        # two are language/codepage pair returned from above

        strInfo = {}
        for propName in propNames:
            strInfoPath = u'\\StringFileInfo\\%04X%04X\\%s' % (lang, codepage, propName)
            ## print str_info
            strInfo[propName] = win32api.GetFileVersionInfo(fname, strInfoPath)

        props['StringFileInfo'] = strInfo
    except:
        pass

    return props

-ChromeDriverAutomation.py-

from getFileProperties import *

chrome_browser = #'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe' -- ENTER YOUR Chrome.exe filepath


cb_dictionary = getFileProperties(chrome_browser) # returns whole string of version (ie. 76.0.111)

chrome_browser_version = cb_dictionary['FileVersion'][:2] # substring version to capabable version (ie. 77 / 76)


nextVersion = str(int(chrome_browser_version) +1) # grabs the next version of the chrome browser

lastVersion = str(int(chrome_browser_version) -1) # grabs the last version of the chrome browser

https://github.com/MattWaller/ChromeDriverAutoUpdate