Azure pipeline throws “Chrome failed to start: crashed.” error on npm test script command

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:

Error Log

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.

1 thought on “Azure pipeline throws “Chrome failed to start: crashed.” error on npm test script command”

  1. According to the error message:

    WebDriverError: unknown error: Chrome failed to start: crashed.
    (unknown error: DevToolsActivePort file doesn't exist)
    
    (The process started from chrome location C:\Program Files(x86)\Google\Chrome\Application\chrome.exe  is no longer running)
    

    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:

    enter image description here

    You could check this ticket for more details.

    Reply

Leave a Comment