skip to Main Content

Faced with an ambiguous problem that I can not solve for about a week.

I use for autotests and decided to deploy my autotests in a docker container but ran into a big problem. Every time I run tests I get this error:

selenium.common.exceptions.WebDriverException: Message: Service /root/.cache/selenium/chromedriver/linux64/116.0.5845.96/chromedriver unexpectedly exited. status code was: 255

I’m using python 3.10, selenium 4.11.2 and pytest 7.4.0.

This is my Dockerfile:

# Use the official Python image.
# https://hub.docker.com/_/python
FROM python:3.10-slim

# Install manually all the missing libraries
RUN apt-get update
RUN apt-get install -y wget gconf-service libasound2 libatk1.0-0 libcairo2 libcups2 libfontconfig1 libgdk-pixbuf2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libxss1 fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils

# Install Chrome
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN dpkg -i google-chrome-stable_current_amd64.deb; apt-get -fy install

# Install Python dependencies.
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . .

CMD ["python3", "-m", "pytest", "--ignore=./tests", "--browser", "headless"]

This is my browser settings:

options = Chrome_Options()
            options.add_argument("--headless")
            options.add_argument("--incognite")
            options.add_argument("--disable-gpu")
            options.add_argument("--single-process")
            options.add_argument("--disable-extensions")
            options.add_argument('--disable-dev-shm-usage')
            options.add_argument("disable-infobars")
            options.add_argument("start-maximized")
            service = Service()
            driver = webdriver.Chrome(
                service=service,
                options=options,
            )

And this is full trace of error:

---------------------------- Captured stderr setup -----------------------------
Traceback (most recent call last):
  File "/app/testsuite/conftest.py", line 161, in init_driver
    driver = webdriver.Chrome(
  File "/usr/local/lib/python3.10/site-packages/selenium/webdriver/chrome/webdriver.py", line 45, in __init__
    super().__init__(
  File "/usr/local/lib/python3.10/site-packages/selenium/webdriver/chromium/webdriver.py", line 53, in __init__
    self.service.start()
  File "/usr/local/lib/python3.10/site-packages/selenium/webdriver/common/service.py", line 109, in start
    self.assert_process_still_running()
  File "/usr/local/lib/python3.10/site-packages/selenium/webdriver/common/service.py", line 122, in assert_process_still_running
    raise WebDriverException(f"Service {self._path} unexpectedly exited. Status code was: {return_code}")
selenium.common.exceptions.WebDriverException: Message: Service /root/.cache/selenium/chromedriver/linux64/116.0.5845.96/chromedriver unexpectedly exited. Status code was: 255

Thanks!

p.s. i’ve added chromium-driver in apt-get and now there are this error:

---------------------------- Captured stderr setup -----------------------------
Traceback (most recent call last):
  File "/app/testsuite/conftest.py", line 161, in init_driver
    driver = webdriver.Chrome(
  File "/usr/local/lib/python3.10/site-packages/selenium/webdriver/chrome/webdriver.py", line 45, in __init__
    super().__init__(
  File "/usr/local/lib/python3.10/site-packages/selenium/webdriver/chromium/webdriver.py", line 56, in __init__
    super().__init__(
  File "/usr/local/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 206, in __init__
    self.start_session(capabilities)
  File "/usr/local/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 290, in start_session
    response = self.execute(Command.NEW_SESSION, caps)["value"]
  File "/usr/local/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 345, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /root/.cache/selenium/chrome/linux64/116.0.5845.96/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Stacktrace:
#0 0xaaaab79ad8e0 <unknown>
#1 0xaaaab770876c <unknown>
#2 0xaaaab772e6c4 <unknown>
#3 0xaaaab772b814 <unknown>
#4 0xaaaab7766968 <unknown>
#5 0xaaaab77343c4 <unknown>
#6 0xaaaab77357dc <unknown>
#7 0xaaaab7979680 <unknown>
#8 0xaaaab797c4f4 <unknown>
#9 0xaaaab797c0c4 <unknown>
#10 0xaaaab7982e74 <unknown>
#11 0xaaaab797cc0c <unknown>
#12 0xaaaab7957ea0 <unknown>
#13 0xaaaab7995ae8 <unknown>
#14 0xaaaab7995cf8 <unknown>
#15 0xaaaab79a407c <unknown>
#16 0xffff944cee18 <unknown>
#17 0xffff94537e9c <unknown>

------------------------------ Captured log setup ------------------------------
WARNING  selenium.webdriver.common.selenium_manager:selenium_manager.py:133 The chromedriver version (116.0.5845.110) detected in PATH at /usr/bin/chromedriver might not be compatible with the detected chrome version (116.0.5845.96); currently, chromedriver 116.0.5845.96 is recommended for chrome 116.*, so it is advised to delete the driver in PATH and retry

2

Answers


  1. I think that the problem is related to the chromedriver version you are trying to use. If you check this link https://chromedriver.chromium.org/downloads you will notice that there is no chromedriver having version 116.0.5845.96.

    So you should download the chromedriver compatible with Chrome for testing 116. You can download it from here https://googlechromelabs.github.io/chrome-for-testing/#stable corresponding to Linux64 and then you should set the executable path either in your Dockerfile, for example

    # Copy the ChromeDriver executable to the image
    COPY chromedriver /usr/local/bin/
    
    # Set the PATH environment variable to include the directory
    ENV PATH="/usr/local/bin:${PATH}"
    

    (here I assume that the executable chromedriver is located in the directory where your Dockerfile is living) or directly by moving the executable chromedriver in the same folder of your Python script and then modify the following:

    service = Service(executable_path="chromedriver")

    Although you probably need to modify your Dockerfile for the latter as well:

    COPY chromediver chromedriver
    

    Hope this helps

    Login or Signup to reply.
  2. It looks like you’re using the old Chrome headless mode. There’s a new one: https://stackoverflow.com/a/73840130/7058266

    OLD: options.add_argument("--headless")

    NEW: options.add_argument("--headless=new")

    This is especially important if you’re running tests in a Docker container.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search