Reputation: 589
I am trying to run my tests on Azure Devops pipeline and I am getting the below mentioned error. Most solutions are asking to specify (hard-code) the binary path but that can not be implemented on servers. Furthermore, the tests run fine locally.
It seemed like the agents did not have chrome installed, but then again, these tests ran fine on the same agent pool a while back.
NUnit Adapter 3.15.0.0: Test execution complete
X CreateAgentApp [< 1ms]
Error Message:
OneTimeSetUp: OpenQA.Selenium.WebDriverException : unknown error: cannot find Chrome binary
X CreateProject [< 1ms]
Error Message:
OneTimeSetUp: OpenQA.Selenium.WebDriverException : unknown error: cannot find Chrome binary
X CreateSPAApp [< 1ms]
Error Message:
OneTimeSetUp: OpenQA.Selenium.WebDriverException : unknown error: cannot find Chrome binary
I am initializing the ChromeDriver with the following options:
{
ChromeOptions options = new ChromeOptions();
options.AddArgument("--disable-features=VizDisplayCompositor");
return options;
}
Secondly, is it possible to add a demand variable in pipeline settings to check Chrome existence.
Upvotes: 0
Views: 4818
Reputation: 372
I had the same issue and found that chromedriver
and Chrome versions should be compatible. MS hosted agents have both preinstalled as mentioned in other answers (refs: MS-Hosted Agents, Windows-2019/latest).
To ensure the versions work, there are few options depending on the scenario.
If chromedriver
is expected to be in the output directory, e.g. using Selenium.WebDriver.ChromeDriver, then either;
chromedriver
and Chrome of the build server (see refs above) in code; orchromedriver
from the build server to the output directory during build using the environment variable $Env:ChromeWebDriver
.Copy-Item "$env:ChromeWebDriver/chromedriver.exe" -Force -Destination "**/bin/Release/*/"
Alternatively, set the driver path dynamically; maybe checking for the environment variable ChromeWebDriver
.
pseudo-code for illustration only
...
var driverDir = Environment.GetEnvironmentVariable("ChromeWebDriver");
var driverPath = !string.IsNullOrWhiteSpace(driverDir)
? Path.Combine(driverDir, "chromedriver.exe")
: "relative/path"; // see below
// init the driver or add to options
var driver = new ChromeDriver(driverPath)
...
For the relative path, see this question How can I instantiate a new ChromeDriver using a relative path in C#?
Upvotes: 0
Reputation: 30313
Since demands
syntax cannot detect the existence of Chrome.
I manually checked this site.and found Chrome and chromedriver.exe are installed in microsoft-hosted agent pools Hosted Windows 2019 with VS2019 and Hosted VS2017.
You can just run selenium ui tests against these agent pools.
Don't know how you set the chromedriver path? But I found a way to get the chromedriver.exe path of the agents using below powershell scripts. And the path is
C:\SeleniumWebDrivers\ChromeDriver
on agent.
$driverpath = Get-ChildItem Env:ChromeWebDriver
For test purpose i hard code above driver path in my code. The tests ran as expected on hosted agents.
If you dont want to hard code the path, you can add a powershell task to output driver path, and replace the driver path in your test code with the parameters in your test .runsettings files
echo "##vso[task.setvariable variable=chromedriverpath;isOutput=true]$driverpath"
Upvotes: 1