#SharePointProblems | Koskila.net

Solutions are worthless unless shared! Antti K. Koskela's Personal Professional Blog

How to use the right version of the WebDriver on hosted agents in Azure DevOps?

β€’ koskila
Reading Time 9 min
Word Count 1491 words
Comments 25 comments
Rating 5 (7 votes)
View

We were working on getting our Robot Framework tests running during our builds on Azure DevOps. However, using hosted agents, it was quite a struggle to get all of the dependencies on the agent and make sure the tests could access the browser on the build machine.

In our case, we were running the tests in Chrome. For this, we needed Robot Framework and some of its dependencies to be installed on the machine. Luckily, that wasn't too complicated - however, getting the WebDriver that Selenium needs to access Chrome turned out to be tougher!

Basically, you need Python, Robot Framework with its dependencies (these are easy to install with pip), Chrome and a compatible WebDriver on your machine. The emphasis is on "compatible" here, folks. Let's see about your options, here:

How to figure out the right version of the WebDriver?

Microsoft updates the images at their leisure and updates the documentation only if the moon is in the right position. This means that you shouldn't trust whatever information you find online about any versions, and just automate what you can.

Now, I'll show the best option first, and your possible fallbacks afterwards:

Use the preinstalled WebDriver, if it's available

At least some images Microsoft offers have the WebDriver preinstalled. The chrome version might be whatever, but the WebDriver should be compatible.

Funnily enough, while Microsoft might install the WebDriver, they leave out the crucial step: adding it to PATH environment variable. That means that your Robot Framework won't get access to the WebDriver - you'd need to either hardcode the path to your scripts (and nobody wants to do that!) or use the environment variable Microsoft offers for this - yes, they do offer a variable with the location of the WebDriver, but they do not add it to the PATH variable!

Anyway, this variable is usually called "CHROMEWEBDRIVER". Now, in case you don't want to strap that into your Robot Framework tests (and you shouldn't), you can modify your build pipeline to add the value of the variable to PATH instead :)

If this works for you, it's the superior option.

How to add the preinstalled WebDriver's path to PATH environment variable:

pool:
  vmImage: 'windows-2019'

steps:

- pwsh: |
   echo "##vso[task.prependpath]$env:CHROMEWEBDRIVER"
  displayName: Adds ChromeWebDriver for Selenium to PATH 

- powershell: |
   Write-Host "Robot Framework tests"
   robot -x 'outputxunit.xml' '$(Build.SourcesDirectory)\tests\.'
  failOnStderr: true
  displayName: 'Run Robot Framework Tests'
  continueOnError: false

The tests should go through just fine since the WebDriver can be found from PATH :) If this worked for you, don't read further - you're all set, and you shouldn't even consider any of the workaround steps below.

Now, in case that didn't work - here's some further investigation:

Install the WebDriver yourself

Augh - installing WebDrivers sucks, but luckily there are tools to help you out - webdrivermanager being one of them (there are at least 3 tools with that name, but let's just roll with it).

Now, this is how you can easily install the WebDriver using WebDriverManager, and it'll get added to the PATH automagically:

# Using WebDriver Manager to download and fix environment variable:
# https://stackoverflow.com/questions/56754918/setting-chrome-driver-executable-path-keeps-causing-my-build-to-fail
- script: webdrivermanager chrome --linkpath AUTO

The tricky part is that the version needs to be the correct one. By default, it'll use the latest one available - but the images can have whichever version of Chrome.

First, let me tell you how it should be done according to the documentation, and then let me tell you how it actually works.

Find out the Chrome version from Microsoft's documentation

Microsoft has great documentation on the different Microsoft-hosted agents and their installed software. It's included at the end of this blog post. Below is an example of the documentation for an image:

Microsoft's documentation detailing the version of Google Chrome installed on a hosted build agent

Microsoft's documentation detailing the version of Google Chrome installed on a hosted build agent

Of course, please note that the list of software might be outdated, as even though it's supposed to be automatically updated, I don't think it works very reliably. People on this issue found that out the hard way, just like I did:

https://github.com/microsoft/azure-pipelines-image-generation/issues/1340

So, the actual solution?

How to find out the Chrome version and use it as the version of your WebDriver?

Relying on the documentation backfired on us quite badly, as we spent a few hours trying to get the Chrome WebDriver to load and start the robot tests - but it was complaining about the version of Google Chrome not being 75. We were installing version 75 WebDriver as shown above since that's what Microsoft's documentation claimed was installed on the image.

Well, duh, it really wasn't. But the latest version of the WebDriver (likely for Chome 78) didn't work either. Then, what to do?

How to find out the right version of Google Chrome?

  1. Using the PowerShell below, you can find the version of Chrome installed on a machine (like your dev box):

    ((Get-Item "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe").VersionInfo)

    The output should look something like this:

    The PowerShell one can use to find out the Chrome version on a machine.
    The PowerShell one can use to find out the Chrome version on a machine.

    This applies to most desktop machines - but you can also use it on the hosted agents in your YAML, like this:

  2. Use YAML to output the installed Chrome version on the machine:

    - powershell: | Β Β  (Get-Item "C:\Program Files\Google\Chrome\Application\chrome.exe").VersionInfo Β  displayName: 'We want to know the Chrome version installed on this darned machine'

  3. Depending on the image you're using, you might need to change "Program Files" to "Program Files (x86)".

    I even made a nice little script to grab the current Chrome version into a variable, and then use it to download the matching WebDriver. That should work - the WebDriver team says so:

    ChromeDriver uses the same version number scheme as Chrome. See https://www.chromium.org/developers/version-numbers/ for more details.

    - - We always provide ChromeDriver for the current Stable and Beta versions of Chrome. However, if you use Chrome from Dev or Canary channel, or build your own custom version of Chrome, It is possible that there is no available ChromeDriver that officially supports it. In this case, please try the following: https://sites.google.com/a/chromium.org/chromedriver/downloads/version-selection

    - powershell: | Β Β  $ver = ((Get-Item "C:\Program Files\Google\Chrome\Application\chrome.exe").VersionInfo).ProductVersion Β  Β echo "##vso[task.setvariable variable=ChromeVersion;isOutput=true]$ver" Β  name: GetChromeVersion Β  displayName: 'We want to know the Chrome version installed on this darned machine' Β  - script: webdrivermanager chrome:$(GetChromeVersion.ChromeVersion) --linkpath AUTO Β  displayName: 'Manage Chrome webdriver version'

    However, the patch numbers don't necessarily match - and the WebDriverManager -libraries I've found so far don't have the necessary logic to download the correct version of the WebDriver.

    So the script above doesn't work for all cases. And since we need something that actually DOES work, here's a simple way to set the variable for the build pipeline itself, and just update it if a new major version gets deployed to the agent again (even if the major version is wrong in Microsoft's documentation was a fun surprise...)

  4. set a variable for a version of Chrome that's supported by a WebDriver and use that for your tests

    - powershell: | Β Β  (Get-Item "C:\Program Files\Google\Chrome\Application\chrome.exe").VersionInfo Β  displayName: 'We want to know the Chrome version installed on this darned machine' Β  - script: pip install robotframework robotframework-pabot robotframework-seleniumlibrary webdrivermanager Β  displayName: 'Install Python dependencies' Β  - script: webdrivermanager chrome:$(ChromeVersion) --linkpath AUTO Β  displayName: 'Manage Chrome webdriver version' Β  - powershell: | Β Β  Write-Host "Robot Framework tests" Β Β  robot -x 'outputxunit.xml' '$(Build.SourcesDirectory)\tests\.' Β  failOnStderr: true Β  displayName: 'Run Robot Framework Tests' Β  continueOnError: true

    And the variable is set as so:

    Azure DevOps Build Pipeline Variable configuration
    Azure DevOps Build Pipeline Variable configuration

    You need to use a Chrome version that has a WebDriver released for it. This website has a list of possible values: https://chromedriver.chromium.org/downloads


With that workaround, you should be good, until Microsoft updates the images. And at that point, you'll see the new version of Chrome in the build output for the task we left at the top for outputting the Chrome version with PowerShell! :)

Table of agent images hosted by Microsoft

Image Classic Editor Agent Specification YAML VM Image Label Included Software
Windows Server 2019 with Visual Studio 2019 windows-2019 windows-latest OR windows-2019 Link
Windows Server 2016 with Visual Studio 2017 vs2017-win2016 vs2017-win2016 Link
Windows Server 2012 R2 with Visual Studio 2015 vs2015-win2012r2 vs2015-win2012r2 Link
Windows Server Core 1803 (for running Windows containers) win1803 win1803 Link
Ubuntu 18.04 ubuntu-18.04 ubuntu-latest OR ubuntu-18.04 Link
Ubuntu 16.04 ubuntu-16.04 ubuntu-16.04 Link
macOS X Mojave 10.14 macOS-10.14 macOS-latest OR macOS-10.14 Link
macOS X High Sierra 10.13 macOS-10.13 macOS-10.13 Link

The list has been last updated on 26.1.2020. If you want to check out the latest version, you can do that on docs.microsoft.com.

You can simply find the right image from the table above, click the link to the list of installed software, and use that info in your scripts. I mean, if it's updated. Don't rely on that too much!

References

Comments

Interactive comments not implemented yet. Showing legacy comments migrated from WordPress.
SimonWCC
2019-11-20 04:24:42)
Thanks, you save my day~
2019-11-20 07:27:27
Thanks for your comment, Simon - happy to be of help! :)
2019-12-01 21:01:36)
Thanks for creating this post. I added the bits of code you mentioned at the start of the article, to a basic Azure Pipeline YAML file. I ran it, and got robot : The term 'robot' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At D:\a\_temp\5fbce742-ff63-4e76-b91d-ee238386d389.ps1:3 char:1 + robot -x 'outputxunit.xml' 'd:\a\1\s\tests\.' + ~~~~~ + CategoryInfo : ObjectNotFound: (robot:String) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : CommandNotFoundException PowerShell exited with code '1'. so I might have to figure out how to add robot into the windows-2019 vmware image.
2019-12-10 21:52:30
Hi Esa, Thanks for the comment and an insightful question! This was mostly my oversight. Should've included the step to install dependencies in the YAML! I added it now - but here it is for your reference: - script: pip install robotframework robotframework-pabot robotframework-seleniumlibrary webdrivermanager displayName: 'Install dependencies' I might need to restructure the article(s) a bit, since this one is kind of becoming a mess... Anyway, let me know how it goes!
Sai
2020-02-06 22:20:04)
I am using Selenium-Java-Maven for my automation. My local build runs fine but Azure DevOps fails. I added your yaml code as mentioned below but no luck. You mentioned about Python, how to solve if i'm using Java and i'm using WebDriverManager in my script. Please help! trigger: - master pool: vmImage: 'ubuntu-latest' steps: - task: Maven@3 inputs: mavenPomFile: 'NextGen/pom.xml' mavenOptions: '-Xmx3072m' javaHomeOption: 'JDKVersion' jdkVersionOption: '1.8' jdkArchitectureOption: 'x64' publishJUnitResults: true testResultsFiles: '**/surefire-reports/TEST-*.xml' goals: 'package' # Using WebDriver Manager to download and fix environment variable: # https://stackoverflow.com/questions/56754918/setting-chrome-driver-executable-path-keeps-causing-my-build-to-fail - script: webdrivermanager chrome --linkpath AUTO
Sai
2020-02-07 01:28:08
I did not set path for chrome driver. Below command worked echo "##vso[task.prependpath]$env:CHROMEWEBDRIVER" Thank you!
Joris
2020-02-18 13:28:03)
For some reason I cant seem to load the value from the CHROMEWEBDRIVER variable, the line #echo "##vso[task.prependpath]$env:ChromeWebDriver" errors because prependpath cant handle a null value. I'm using the windows-2019 image and I just cant understand why it wont load the variable. I tried loading it into a pipeline scoped variable as well but nothing is in there, any ideas? I should probably note that this is in a build pipeline, not a release pipeline, maybe that matters?
2020-02-19 23:01:15
Just to narrow the scope down a bit, could you try running it on vs2017-win2016 instead? If you just grab the Chrome version to a variable and install the webdriver during the execution, does that work for you?
Punit
2020-02-19 11:30:59)
I want to use Java version 11 for my scripts on the Dev Azure Azent. Tried setting the Java_home though CMD task on my pipeline. - task: CmdLine@2 inputs: script: | echo %JAVA_HOME% setx -m JAVA_HOME "C:\Program Files\Java\zulu-11-azure-jdk_11.33.15-11.0.4-win_x64\" I am getting success message on the logs, but JAVA_HOME is still not updated. Could you please help on this.
2020-02-20 00:24:45
Configuring Azure DevOps builds for Java is a bit off my turf - perhaps getting in touch with the team on Twitter would be the best option here? πŸ€”
Brian
2020-05-29 02:38:38)
Getting an error on the "script: webdrivermanager chrome:$(ChromeVersion) --linkpath AUTO" task. Error, unable to find appropriate download for win64 This is on the hosted windows 2019. Is there a solution to this error? pip install works successfully.
2020-06-01 22:57:53
Hi Brian, Sounds like webdrivermanager is failing to find the appropriate download for your combination of Operating System and Google Chrome version! What's the value of the ChromeVersion variable?
2020-07-28 05:26:30)
Thank you dude, this helps a lot in understanding what goes on in azure since Microsoft doesn't take the time to provide better information. I wouldn't be surprised if they point to your link for help in their tech support.
Antti K. Koskela
2020-07-28 22:24:47
Thanks for your kind words! I'll admit it's funny to see which organizations are linking to my blog or accessing the contents from their corporate networks.. πŸ˜… Microsoft is definitely up there!
Neethu Satheesh
2020-10-20 15:15:14)
How Can we update the chrome version in VM
2020-10-20 22:08:12
Hi Neethu and thanks for your comment! Adding something like this as a PowerShell script for your build might work? $theurl = "http://dl.google.com/edgedl/chrome/install/GoogleChromeStandaloneEnterprise64.msi" mkdir c:\tmp $output = "c:\tmp\chrome.msi" Invoke-WebRequest -Uri $theurl -OutFile $output -ErrorAction SilentlyContinue msiexec /q /i c:\tmp\chrome.msi start-sleep -Seconds 300 # sleep for 5 mins just to allow updates to be processed Remove-Item -Path c:\tmp\chrome.msi –Force
Jose Luis Latorre
2021-04-27 15:45:48)
Hi, cool article! looking forward to putting it into practice... Just how do I tell my .NET test assembly that contains the WebDriver NuGet package to use the one I just installed on the system?
Antti K. Koskela
2021-05-14 22:54:33
Thanks for your comment, Jose! I'm sorry but I totally missed your comment! I got a wave of pingbacks and spam comments which I left unapproved for further processing, and yours got buried under it. Anyway... I don't actually quite understand your question, either :D What're you doing that isn't working?
utkarsh bandekar
2021-10-13 09:38:55)
I want to install chrome along with chrome driver. I am new to this. Can you help with powershell script
2021-11-05 13:13:29
Hi Utkarsh, Not sure if this will help in your particular case, but in general the PowerShell script for downloading and installing Google Chrome would look somewhat like this: $Path = $env:TEMP; $Installer = "chrome_installer.exe"; Invoke-WebRequest "http://dl.google.com/chrome/install/854.0/chrome_installer.exe" -OutFile $Path\$Installer; Start-Process -FilePath $Path\$Installer -Args "/silent /install" -Verb RunAs -Wait; Remove-Item $Path\$Installer
Whitewater Magpie Ltd.
β€’
Β© 2025
Static Site Generation timestamp: 2025-08-21T07:25:11Z