jkosmala
jkosmala

Reputation: 94

running ChromeDriver on Docker [SpecFlow]

When I run SpecFlow tests on Windows everything is fine.

The issue starts when I run on Linux (WSL and Docker - both Ubuntu based), the run ends up with following StackTrace:

OpenQA.Selenium.WebDriverException : unknown error: Chrome failed to start: crashed.
  (chrome not reachable)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)


Stack trace:

   at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse, String commandToExecute)
   at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.WebDriver.StartSession(ICapabilities desiredCapabilities)
   at OpenQA.Selenium.WebDriver..ctor(ICommandExecutor executor, ICapabilities capabilities)
   at OpenQA.Selenium.Chromium.ChromiumDriver..ctor(ChromiumDriverService service, ChromiumOptions options, TimeSpan commandTimeout)
   at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)
   at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeDriverService service, ChromeOptions options)

The code to create ChromeDriver instance:

public static WebDriver InitializeChromeDriver()
{

var chromeDriverService = ChromeDriverService.CreateDefaultService();
var chromeOptions = new ChromeOptions();
chromeOptions.AddArguments("--headless", "--remote-debugging-port=9222", "--no-sandbox",
            "--disable-dev-shm-using",
            "--disable-extensions",
            "--disable-gpu",
            "start-maximized", 
             "--window-size=1920,1080");
var chromeDriver = new ChromeDriver(chromeDriverService, chromeOptions);
return chromeDriver;
}

For Docker, I used following setup

RUN echo "deb http://dl.google.com/linux/chrome/deb/ stable main" | \
    tee -a /etc/apt/sources.list.d/google.list && \
    wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | \
    apt-key add - && \
    apt-get update && \
    apt-get install -y google-chrome-stable libxss1

RUN apt-get install -yqq unzip
RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip
RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin

Base image: mcr.microsoft.com/dotnet/sdk:6.0

I don't have any idea what is wrong in setup itself or maybe something is wrong with SpecFlow on Ubuntu?

I was looking on other posts on StackOverflow but nothing from advised solutions worked for me.

Upvotes: 0

Views: 383

Answers (1)

Greg Burghardt
Greg Burghardt

Reputation: 18888

Currently the API endpoint http://chromedriver.storage.googleapis.com/LATEST_RELEASE is returning 105.0.5195.52 for a version number. You have Chrome 104 installed. The ChromeDriver and Chrome major versions need to match. You will need ChromeDriver v104.x.

The "latest version" API is not what you want. You need the matching version for your Chrome installation. This is a little tricky. You want the latest release for a particular Chrome version, which requires a different API endpoint:

https://chromedriver.storage.googleapis.com/LATEST_RELEASE_<version>

You will need to replace the <version> token with the major version of Chrome installed. For example, you have Chrome 104.0.5112.79 installed, so you need to hit the following API endpoint:

https://chromedriver.storage.googleapis.com/LATEST_RELEASE_104
                                                           ^^^

As of writing this answer, the API endpoint above is returning 104.0.5112.79. This makes the full URL to the zip file:

http://chromedriver.storage.googleapis.com/104.0.5112.79/chromedriver_linux64.zip

The Version Selection page at Chromium.org has more information on public APIs that return ChromeDriver versions.

Upvotes: 1

Related Questions