3
votes

I recently created a self-hosted Azure DevOps Agent and installed with Google Crome as well. Is it possible to install Chrome Driver on this server and can I select a specific version to be used?

I'd like for Chrome Driver 2.42.0.1 to be used by this Self-hosted Agent.

Any help will be much appreciated. Thanks!

3
What is your pipeline? where you want the agent use the driver?Shayki Abramczyk
Hi @ShaykiAbramczyk, our QA wants to use it for their for UI Testing Automation projects. Thank youadrio
If you install only 2.42.0.1 so I guess the agent use this version... because this is the installed one... if your question it's about the pipeline so you need to share the pipeline and where in the pipeline you run the UI testing.Shayki Abramczyk
It is possible, you might need to write a powershell to install this but it is possible. i don't know your test-project but if you use a .net test you can bring your chromedriver via nuget and then in the buildoutput of the tests, this would be better then installing chromedriverD.J.
thanks @ShaykiAbramczyk & @ D.J - I was already able to install it thru the steps here: npmjs.com/package/chromedriver :)adrio

3 Answers

4
votes

One more solution to use Microsoft-hosted agents with already installed Chrome browser chrome driver.

Agents already contain environment variable with ChromeWebDriver location on Agent (It works for "windows-2019" and "vs2017-win2016" Microsoft-hosted agents). Also firefox and IE drivers exists on Agents (https://github.com/actions/virtual-environments/blob/master/images/win/Windows2019-Readme.md).

C# code:

ChromeOptions chromeOptions = new ChromeOptions();
var driverPath = Path.Combine(Directory.GetCurrentDirectory());
var envChromeWebDriver = Environment.GetEnvironmentVariable("ChromeWebDriver");
if(!string.IsNullOrEmpty(envChromeWebDriver) &&
   File.Exists(Path.Combine(envChromeWebDriver, "chromedriver.exe")))
{
    driverPath = envChromeWebDriver;
}
ChromeDriverService defaultService = ChromeDriverService.CreateDefaultService(driverPath);
defaultService.HideCommandPromptWindow = true;
var driver = (IWebDriver) new ChromeDriver(defaultService, chromeOptions);
1
votes

Installation I found using npm install here: :)

https://www.npmjs.com/package/chromedriver

1
votes

This may be a late post but to help out the forum, which has helped me since almost a decade, here is how we sorted it out.

By default the "Azure Pipelines Hosted VS2017 image" (Or in Classic Editor Agent Specification its called vs2017-win2016) already has Google Chrome (Version 77.0.3865.90 as on 3rd December 2019) and ChromeDriver (77.0.3865.40 as on 3rd December 2019) pre-installed (More info here - https://github.com/Microsoft/azure-pipelines-image-generation/blob/master/images/win/Vs2017-Server2016-Readme.md)

But we still faced the issue of "selenium-side-runner" not able to find the ChromeDriver due to the missing PATH in the System Variables of Environment variable in Windows.

Image - Chrome Driver Not found

So we tried digging in a bit deeper and found that we could achieve this by uploading the ChromeDriver through the Build process and then copying that into the NodeJs folder within C:Program Files..! Sweet?

Lets walk through the steps briefly to see how this is achieved.

  1. We first have to visit https://chromedriver.chromium.org/downloads and search for the version of the driver matching the version on Chrome installed on the Hosted Agent (Version 77 in our case as on date)
  2. Next we create a folder in our Azure Repos and push both the Chromedriver.exe and our Sample.side file in that folder (Side file can be named per your preference, and this is generated from the Selenium IDE) Adding ChromeDriver.exe and sample.side file in the Repo
  3. Now we create the Build process to just zip the contents of this folder and create an Artifact from this to be consumed in the Release Pipeline. Build Pipeline explained
  4. Next we build the Release Pipeline and ensure that the vs2017-win2016 Agent is taken
  5. The steps assigned to the Agent include:
  6. Extracting of the zip file
  7. Installing the Selenium Side Runner by using NPM and custom Command - "install -g selenium-side-runner"
  8. We then have to copy the ChromeDriver.exe from the extracted files to "C:\Program Files\nodejs" folder using command prompt - copy "chromedriver.exe" "C:\Program Files\nodejs"
  9. The final step would be to run the "selenium-side-runner" command - selenium-side-runner sample.side
  10. We would see the test result at the end of the task by checking the log file for the task.

Hope this helps..!