I’m trying to run a test script in Azure DevOps pipelines and I’ve been struggling to get selenium to run Chrome. I always get the following error:
WebDriverError: unknown error: Chrome failed to start: crashed.
(unknown error: DevToolsActivePort file doesn't exist)
I’ve looked at many similar questions but no luck. This only happens on Azure DevOps pipelines. It works on my local and if I login into the server and locate the source code from the build agent, I can run "npm run test" successfully.
Here is the detailed error log from Azure DevOps:
Below is the JavaScript code that is triggered when running the script:
const { Given, When, Then, AfterAll } = require('@cucumber/cucumber');
const { until, Builder, By, Capabilities } = require('selenium-webdriver');
const { expect } = require('chai');
// WebDriver Setup (for Chrome)
const capabilities = Capabilities.chrome();
const chrome = require('selenium-webdriver/chrome');
const chromeService = chrome.setDefaultService(new chrome.ServiceBuilder('chromedriver.exe').build())
const options = new chrome.Options();
options.addArguments('--headless');
options.addArguments('--no-sandbox');
options.addArguments('--disable-dev-shm-usage');
const driver = new Builder().withCapabilities(capabilities)
.setChromeOptions(options)
.setChromeService(chromeService)
.build();
Also, both chrome driver and the browser are using the same version.
Thanks for your help.
According to the error message:
It implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
Your main issue is the Chrome browser is not installed at the default location within your system.
The server i.e. ChromeDriver expects you to have Chrome installed in the default location for each system as per the image below:
You could check this ticket for more details.