SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.56k stars 8.17k forks source link

[🐛 Bug]: After Upgrading to Chrome for Testing getting 'Driver server process died prematurely' #12586

Closed EuclidHeron closed 1 year ago

EuclidHeron commented 1 year ago

What happened?

I have the following Docker file (see below) which downloads the executables for the 'Chrome for Testing' and 'ChromeDriver'. But hwen I try to run my java code (also below) I get an error saying 'Caused by: org.openqa.selenium.WebDriverException: Driver server process died prematurely.'

My Docker code:

FROM maven:3.8.4-openjdk-17
RUN microdnf install -y unzip
ARG CHROME_VERSION=116.0.5845.96
RUN curl -s -o  /tmp/chrome-linux64.zip https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/$CHROME_VERSION/linux64/chrome-linux64.zip \
    && unzip /tmp/chrome-linux64.zip -d /opt \
    && ln -s /opt/chrome-linux64/chrome /usr/local/bin/chrome \
    && rm /tmp/chrome-linux64.zip

ARG CHROME_DRIVER_VERSION=116.0.5845.96
RUN curl -s -o /tmp/chromedriver_linux64.zip https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/$CHROME_DRIVER_VERSION/linux64/chromedriver-linux64.zip \
    && unzip /tmp/chromedriver_linux64.zip -d /opt/selenium \
    && rm /tmp/chromedriver_linux64.zip \
    && mv /opt/selenium/chromedriver-linux64/chromedriver /opt/selenium/chromedriver  \
    && chmod 755 /opt/selenium/chromedriver \
    && ln -s /opt/selenium/chromedriver /usr/bin/chromedriver

ENV CHROMEDRIVER_PORT 4444
ENV CHROMEDRIVER_WHITELISTED_IPS "127.0.0.1"
ENV CHROMEDRIVER_URL_BASE ''
EXPOSE 4444

ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
# For Testing
ENTRYPOINT ["java","-jar", "-Xmx600m","/app.jar"]

My Java code is:

System.setProperty("webdriver.chrome.driver", "/opt/selenium/chromedriver");
            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.addArguments("--headless=new");
            chromeOptions.setBinary("/opt/chrome-linux64/chrome");
            WebDriver webDriver = new ChromeDriver(chromeOptions);

            Stopwatch stopWatch = Stopwatch.createUnstarted();
            stopWatch.start();
            webDriver.get("https://www.google.com/");
            LOGGER.error("Before sleep!");
            Thread.sleep(1000L);
            LOGGER.error("After sleep!");
            String pageSource = webDriver.getPageSource();

I am using maven and have:

<properties>
        <java.version>17</java.version>
<!--        may need to update-->
        <selenium.constructs.version>4.11.0</selenium.constructs.version>
    </properties>

                <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>${selenium.constructs.version}</version>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-api</artifactId>
            <version>${selenium.constructs.version}</version>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-remote-driver</artifactId>
            <version>${selenium.constructs.version}</version>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-chrome-driver</artifactId>
            <version>${selenium.constructs.version}</version>
        </dependency>

Note that prior to Chrome V115 The following Docker file was working:

ARG CHROME_VERSION=113.0.5672.63-1
ADD google-chrome.repo /etc/yum.repos.d/google-chrome.repo
RUN microdnf install -y google-chrome-stable-$CHROME_VERSION \
    && sed -i 's/"$HERE\/chrome"/"$HERE\/chrome" --no-sandbox/g' /opt/google/chrome/google-chrome

## ChromeDriver

ARG CHROME_DRIVER_VERSION=113.0.5672.63
RUN microdnf install -y unzip \
    && curl -s -o /tmp/chromedriver.zip https://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip \
    && unzip /tmp/chromedriver.zip -d /opt \
    && rm /tmp/chromedriver.zip \
    && mv /opt/chromedriver /opt/chromedriver-$CHROME_DRIVER_VERSION \
    && chmod 755 /opt/chromedriver-$CHROME_DRIVER_VERSION \
    && ln -s /opt/chromedriver-$CHROME_DRIVER_VERSION /usr/bin/chromedriver

ENV CHROMEDRIVER_PORT 4444
ENV CHROMEDRIVER_WHITELISTED_IPS "127.0.0.1"
ENV CHROMEDRIVER_URL_BASE ''
EXPOSE 4444

And the (prior) working Java code was:

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments(String.format("user-agent=%s", USER_AGENT));
        chromeOptions.addArguments("--log-level=OFF");
        chromeOptions.addArguments("--headless=new");
//        chromeOptions.setHeadless(true); // deprecated
        List<String> arguments = new LinkedList<>();
        arguments.add("--disable-extensions");
        // disable-infobars no longer works, see the following link for a potential answer:
        // https://stackoverflow.com/questions/57298901/unable-to-hide-chrome-is-being-controlled-by-automated-software-infobar-within
        // also see
        // https://qaautomation.expert/2022/04/01/how-to-disable-infobar-warning-for-chrome-tests-in-selenium/ . Perhaps
        // comment out 'arguments.add("disable-infobars");' in the future or try
        // chromeOptions.setExperimentalOption("excludeSwitches", Arrays.asList("enable-automation")); // <- maybe try this
        // instead of 'arguments.add("disable-infobars");'
        arguments.add("disable-infobars"); // try enabling this to try and save some cpu
        arguments.add("--headless");
        arguments.add("--disable-gpu");
        arguments.add("--no-sandbox");
        arguments.add("--incognito");
        arguments.add("--disable-application-cache");
        arguments.add("--disable-dev-shm-usage");

        chromeOptions.addArguments(arguments);
        return chromeOptions;

        new ChromeDriver(getChromeOptions());

How can we reproduce the issue?

Create the following Docker file:

FROM maven:3.8.4-openjdk-17
RUN microdnf install -y unzip
ARG CHROME_VERSION=116.0.5845.96
RUN curl -s -o  /tmp/chrome-linux64.zip https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/$CHROME_VERSION/linux64/chrome-linux64.zip \
    && unzip /tmp/chrome-linux64.zip -d /opt \
    && ln -s /opt/chrome-linux64/chrome /usr/local/bin/chrome \
    && rm /tmp/chrome-linux64.zip

ARG CHROME_DRIVER_VERSION=116.0.5845.96
RUN curl -s -o /tmp/chromedriver_linux64.zip https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/$CHROME_DRIVER_VERSION/linux64/chromedriver-linux64.zip \
    && unzip /tmp/chromedriver_linux64.zip -d /opt/selenium \
    && rm /tmp/chromedriver_linux64.zip \
    && mv /opt/selenium/chromedriver-linux64/chromedriver /opt/selenium/chromedriver  \
    && chmod 755 /opt/selenium/chromedriver \
    && ln -s /opt/selenium/chromedriver /usr/bin/chromedriver

ENV CHROMEDRIVER_PORT 4444
ENV CHROMEDRIVER_WHITELISTED_IPS "127.0.0.1"
ENV CHROMEDRIVER_URL_BASE ''
EXPOSE 4444

ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
# For Testing
ENTRYPOINT ["java","-jar", "-Xmx600m","/app.jar"]

Then create a ChromedDriver like so:

System.setProperty("webdriver.chrome.driver", "/opt/selenium/chromedriver");
            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.addArguments("--headless=new");
            chromeOptions.setBinary("/opt/chrome-linux64/chrome");
            WebDriver webDriver = new ChromeDriver(chromeOptions);

            Stopwatch stopWatch = Stopwatch.createUnstarted();
            stopWatch.start();
            webDriver.get("https://www.google.com/");
            LOGGER.error("Before sleep!");
            Thread.sleep(1000L);
            LOGGER.error("After sleep!");
            String pageSource = webDriver.getPageSource();
            You will then see the error

### Relevant log output

```shell
Caused by: org.openqa.selenium.WebDriverException: Driver server process died prematurely.
Build info: version: '4.11.0', revision: '040bc5406b'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.49-linuxkit', java.version: '17.0.2'
Driver info: driver.version: ChromeDriver
    at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:237)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:119)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:518)
    ... 104 common frames omitted

Operating System

Ubuntu linux

Selenium version

Java 17

What are the browser(s) and version(s) where you see this issue?

Chrome 116

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver 116.0.5845.96

Are you using Selenium Grid?

No response

github-actions[bot] commented 1 year ago

@EuclidHeron, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

diemol commented 1 year ago

You can still install Chrome similarly; I do not see the need for CfT. Try that, and if it still does not work, you should report it to the Chrome/ChromeDriver folks. Keep in mind that the only thing that changed is the Chrome binary.

I've included links to report a bug to Chrome below.

github-actions[bot] commented 1 year ago

Hi, @EuclidHeron. This issue has been determined to require fixes in ChromeDriver.

You can see if the feature is passing in the Web Platform Tests.

If it is something new, please create an issue with the ChromeDriver team. Feel free to comment the issues that you raise back in this issue. Thank you.

dwilliams-gs commented 12 months ago

Hi @diemol - I've having a very similar issue to yourself since moving to using CfT. Did you manage to get this resolved?

titusfortner commented 12 months ago

Google needs to resolve it, there isn't anything we can do about it.

github-actions[bot] commented 10 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.