I’m running python 3.12. Both chrome for testing and chrome driver are the same version i.e. 123.0.6312.58 – this has been checked and verified
It’s working perfectly fine on my Mac. However when I run the dockerized app I get the error
024-03-20 19:53:58 03/20/2024 06:53:58PM - ERROR - helper_functions.py::helper_functions::__init__:36 - Chrome driver exception: Message: session not created: Chrome failed to start: crashed.
2024-03-20 19:53:58 (disconnected: unable to connect to renderer)
2024-03-20 19:53:58 (The process started from chrome location /usr/local/bin/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
2024-03-20 19:53:58 Stacktrace:
2024-03-20 19:53:58 #0 0x555555cc9993 <unknown>
2024-03-20 19:53:58 #1 0x5555559c4136 <unknown>
2024-03-20 19:53:58 #2 0x5555559f8448 <unknown>
2024-03-20 19:53:58 #3 0x5555559f443d <unknown>
2024-03-20 19:53:58 #4 0x555555a3d239 <unknown>
My docker config looks like this
FROM --platform=linux/amd64 ubuntu:20.04
ENV PATH /usr/local/bin:$PATH
RUN set -eux;
apt-get update &&
apt-get install -y --no-install-recommends
ca-certificates
tzdata
wget
unzip
;
RUN apt-get install -y git
RUN apt-get install -y python3.12
RUN apt-get install -y python3-pip
RUN apt-get update && apt-get install -y libgbm1 gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3
libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libnss3 lsb-release xdg-utils wget ca-certificates
RUN set -eux;
wget -O chrome-linux64.zip https://storage.googleapis.com/chrome-for-testing-public/123.0.6312.58/linux64/chrome-linux64.zip &&
unzip chrome-linux64.zip &&
mv chrome-linux64/* /usr/local/bin/ &&
chmod +x /usr/local/bin/chrome &&
rm -rf chrome-linux64.zip chrome-linux64
RUN set -eux;
wget -O chromedriver-linux64.zip https://storage.googleapis.com/chrome-for-testing-public/123.0.6312.58/linux64/chromedriver-linux64.zip &&
unzip chromedriver-linux64.zip &&
mv chromedriver-linux64/chromedriver /usr/local/bin/chromedriver &&
chmod +x /usr/local/bin/chromedriver &&
rm -rf chromedriver-linux64.zip chromedriver-linux64
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
RUN mkdir /home/test
WORKDIR /home/test
COPY . .
ENTRYPOINT ["behave"]
CMD ["-v", "features/scenarios", "-D", "browser=chrome", "-f", "html", "-o", "test-results/report.html"]
Environment
- Selenium 4.18
- Ubuntu Linux Docker image
- Behave 1.2.7dev5
2
Answers
It’s tricky to get Chrome running in Docker. I tried running a container off
Dockerfile
like yours and got similar errors. Passing these additional Chrome CLI arguments upon Selenium driver creation worked for me:Try updating your
selenium.webdriver.Chrome
creation code used by Behave in a similar fashion. Hope this helps.What those arguments do and other possible related problems are described in those references:
PS. A complete minimal reproducible example would be really useful. Without it, one could only guess about your specific problem.
PPS. Judging by your
Dockerfile
, you’re still using Python 3.8 (not 3.12) in your container. Beware of other problems this may create 🙂Try peeking into your container with
docker exec -it <mycontainer> bash
to verify thatpip
,python3
(andbehave
) all resolve to the default system python environment, which is python 3.8 forubuntu:20.04
base image.You try to install 3.12 though. Pay attention to build logs (
docker build --progress=plain
helps). When you doapt-get install -y python3.12
it says:So no
python3.12
gets installed (and even if it did, it wouldn’t activate 3.12 environment on a system level, so just callingpip
isn’t enough to use it). You could try choosing another base image or, for example, setting up your python env via pyenv for the sake of simplicity.Check dockerfile if it has all the necessary libs, something like that would help: