0

I'm using Selenium to run tests using Chrome Webdriver. Most of the time script works fine, but sometimes it returns a Timeout error when initializing webdriver.Chrome() constructor.

Below is the error message I'm receiving.

    Message: session not created
source-app-1  | from timeout: Timed out receiving message from renderer: 600.000
source-app-1  |   (Session info: headless chrome=102.0.5005.182)

I see this failure at a rate of about 1 in 10 or sometimes about 1 in 20.

Below is the code when it sometimes hangs and returns the Timeout exception.

from selenium import webdriver

self.driver = webdriver.Chrome(executable_path=driver_executable_path,
                                 chrome_options=driver_options)

ENVIRONMENT

The script runs inside the Docker container and below is my dockerfile.

FROM nginxinc/nginx-unprivileged:1-alpine
ENV PATH="/scripts:${PATH}"

USER root

# Install python/pip
ENV PYTHONUNBUFFERED=1
RUN apk add --update --no-cache python3=3.9.15-r0 py3-setuptools  --repository=https://dl-cdn.alpinelinux.org/alpine/v3.15/main/
RUN ln -sf python3 /usr/bin/python
RUN python3 -m ensurepip
RUN pip3 install  --upgrade --no-cache pip


COPY ./requirements.txt /requirements.txt

RUN apk add --update --no-cache gcc libffi-dev libc-dev linux-headers openssl-dev cargo rust python3-dev libxml2-dev libxslt-dev jpeg-dev zlib-dev chromium chromium-chromedriver --repository=https://dl-cdn.alpinelinux.org/alpine/v3.15/main/
RUN pip3 install -r /requirements.txt


RUN mkdir -p /vol/static
RUN chmod 755 /vol/static



RUN mkdir /app
COPY . /app
WORKDIR /app


RUN adduser -D user
RUN chown -R user:user /vol
RUN chmod -R 755 /vol/web

CMD ["entrypoint.sh"]

Docker Compose

version: '3.7'
services:
  app:
    build:
      context: .
    command: sh -c "python start.py"
    deploy:
      resources:
        limits:
          cpus: "2"
          memory: 2048M
        reservations:
          cpus: "0.25"
          memory: 128M
    volumes:
      - .:/app
    environment:
      ...


networks:
  default:
    external:
      name: my-network
Arman Avetisyan
  • 349
  • 2
  • 10
  • Does this answer your question? [Selenium Timed out receiving message from renderer](https://stackoverflow.com/questions/48450594/selenium-timed-out-receiving-message-from-renderer) – Aadarsha Dec 23 '22 at 04:52
  • I've checked that answer and tried all the specified solutions but still facing the same issue. Unfortunately, there is no accepted solution in that post. – Arman Avetisyan Dec 23 '22 at 04:56
  • That likely means that there is a network enpoint that isn't responding or some javascript code the isn't rendering or some other reason... that is why you should set timeouts. – Alexander Dec 23 '22 at 06:04
  • Thanks, Alexander. I'm testing it against the same URL address over and over and it appears randomly. Do you mean set timeouts for webdriver? If yes then, the problem is the driver should be initialized so I can set the timeouts right? but the timeout happens when I'm calling the constructor. webdriver.Chrome() . pls let me know if I'm missing something. FYI... the solution should be universal, which means I can't hardcode it to wait for some specific tags in the DOM – Arman Avetisyan Dec 23 '22 at 06:17
  • Could you please confirm: 1. if this is working in non-headless mode? 2. Based on the log above, I think that you are in Docker environment, so I assume that you have installed chromedriver in Docker as well. Please share your Dockerfile and compose.yml. You might have to ensure some configs in Docker environment. 3. Please share a bit more context of the log and also more codebase that includes the options and executable path you are using in the shared code snippet. – Aadarsha Dec 23 '22 at 06:45
  • I haven't tested it in non-headless mode. It returns some other errors when. I run it in non-headless mode but it's not related to this issue. It has to be --in headless mode It's a requirement. It runs in a docker container and most of the time it works as expected. I've updated the question with the dockerfile. – Arman Avetisyan Dec 23 '22 at 19:05

0 Answers0