What if you use chromedriver for Selenium Web testing of your application? When new version of Google Chrome is out, the developers gets frustrated why does their tests are made unstable again?
There was some level of compatibility between chrome and chromedriver versions: chromedrivers has support for three latest released. But I found this has changed recently. The chromedriver 2.46 release was the latest release with "last three releases" supports policy.
Now chromedriver and chrome versions are coincide in MAJOR.MINOR.PATCH
triad. Fourth number may differ when patches for current version are become available.
There is new version selector guide which is explain how you can select right chromedriver version for your current chrome.
Here is excerpt:
Here are the steps to select the version of ChromeDriver to download:
- First, find out which version of Chrome you are using. Let's say you have Chrome 72.0.3626.81.
- Take the Chrome version number, remove the last part, and append the result to URL "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_". For example, with Chrome version 72.0.3626.81, you'd get a URL "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_72.0.3626".
- Use the URL created in the last step to retrieve a small file containing the version of ChromeDriver to use. For example, the above URL will get your a file containing "72.0.3626.69". (The actual number may change in the future, of course.)
- Use the version number retrieved from the previous step to construct the URL to download ChromeDriver. With version 72.0.3626.69, the URL would be "https://chromedriver.storage.googleapis.com/index.html?path=72.0.3626.69/".
- After the initial download, it is recommended that you occasionally go through the above process again to see if there are any bug fix releases.
This is painful for me to manually update chromedriver when I found that chrome version has changed. I'd like to automate this.
And here is powershell script I've wrote. The requirements was:
chromedriver.exe
located inSelenium
folder of my project (you can customize it with$chromeDriverRelativeDir
variable)- script fetches chromedriver version from
https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$chromeDriverExpectedVersion
URL$chromeDriverExpectedVersion
isMAJOR.MINOR.PATCH
version of current installed chrome- URL contains latest full version of chromedriver, I'll store it in
$chromeDriverLatestVersion
variable
- script downloads chromedriver version from
https://chromedriver.storage.googleapis.com/$chromeDriverLatestVersion/chromedriver_win32.zip
- script then unpacks contents of downloaded zip archive for inplace update of chromedriver executable
- special handling used for
chrome versions < 73
- use chromedriver v2.46 - special handling used if no need to update existing chromedriver
$thisScriptRoot = if ($PSScriptRoot -eq "") { "." } else { $PSScriptRoot }
$chromeDriverRelativeDir = "Selenium"
$chromeDriverDir = $(Join-Path $thisScriptRoot $chromeDriverRelativeDir)
$chromeDriverFileLocation = $(Join-Path $chromeDriverDir "chromedriver.exe")
$chromeVersion = [System.Diagnostics.FileVersionInfo]::GetVersionInfo("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe").FileVersion
$chromeMajorVersion = $chromeVersion.split(".")[0]
if (-Not (Test-Path $chromeDriverDir -PathType Container)) {
$dir = New-Item -ItemType directory -Path $chromeDriverDir
}
if (Test-Path $chromeDriverFileLocation -PathType Leaf) {
# get version of current chromedriver.exe
$chromeDriverFileVersion = (& $chromeDriverFileLocation --version)
$chromeDriverFileVersionHasMatch = $chromeDriverFileVersion -match "ChromeDriver (\d+\.\d+\.\d+(\.\d+)?)"
$chromeDriverCurrentVersion = $matches[1]
if (-Not $chromeDriverFileVersionHasMatch) {
Exit
}
}
else {
# if chromedriver.exe not found, will download it
$chromeDriverCurrentVersion = ''
}
if ($chromeMajorVersion -lt 73) {
# for chrome versions < 73 will use chromedriver v2.46 (which supports chrome v71-73)
$chromeDriverExpectedVersion = "2.46"
$chromeDriverVersionUrl = "https://chromedriver.storage.googleapis.com/LATEST_RELEASE"
}
else {
$chromeDriverExpectedVersion = $chromeVersion.split(".")[0..2] -join "."
$chromeDriverVersionUrl = "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_" + $chromeDriverExpectedVersion
}
$chromeDriverLatestVersion = Invoke-RestMethod -Uri $chromeDriverVersionUrl
Write-Output "chrome version: $chromeVersion"
Write-Output "chromedriver version: $chromeDriverCurrentVersion"
Write-Output "chromedriver latest: $chromeDriverLatestVersion"
$needUpdateChromeDriver = $chromeDriverCurrentVersion -ne $chromeDriverLatestVersion
if ($needUpdateChromeDriver) {
$chromeDriverZipLink = "https://chromedriver.storage.googleapis.com/" + $chromeDriverLatestVersion + "/chromedriver_win32.zip"
Write-Output "Will download $chromeDriverZipLink"
$chromeDriverZipFileLocation = $(Join-Path $chromeDriverDir "chromedriver_win32.zip")
Invoke-WebRequest -Uri $chromeDriverZipLink -OutFile $chromeDriverZipFileLocation
Expand-Archive $chromeDriverZipFileLocation -DestinationPath $(Join-Path $thisScriptRoot $chromeDriverRelativeDir) -Force
Remove-Item -Path $chromeDriverZipFileLocation -Force
$chromeDriverFileVersion = (& $chromeDriverFileLocation --version)
Write-Output "chromedriver updated to version $chromeDriverFileVersion"
}
else {
Write-Output "chromedriver is actual"
}
Summary
I wrote powershell script which I could run in build agent right before selenium web tests. It will check current chrome version on build agent and will update chromedriver accordingly.
Happy selenium web testing!
Comments