简体   繁体   中英

Installing ChromeDriver on self-hosted Azure DevOps Agent

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!

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);

Installation I found using npm install here: :)

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

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..!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM