Cerin
Cerin

Reputation: 64709

Selenium crashing in Docker due to Browsing context has been discarded

How do you run Selenium based tests inside Docker?

I'm trying to get some Python+Selenium tests, which use Firefox and Geckodriver, to run under an Ubuntu 18 Docker image.

My docker-compose.yml file is simply:

version: "3.5"
services:
  app_test:
    build:
      context: .
      shm_size: '4gb'
      mem_limit: 4096MB
      dockerfile: Dockerfile.test

Unfortunately, most tests are failing with errors like:

selenium.common.exceptions.NoSuchWindowException: Message: Browsing context has been discarded

The few search results I can find mentioning this error suggest it's because of low memory. The server I'm running the tests on has 8GB of total memory, although I also tested on a machine with 32GB and received the same error.

I also added a call to print the output of top before each test, and it's showing virtually no memory usage, so I'm not sure what would be causing the test to crash due to insufficient memory.

Some articles suggested adding the shm_size and mem_limit lines, but those had no effect.

I've also tried different versions of Firefox, from the most recent 71 version to the older ESR releases, to rule out it's not a bug due to incompatible versions of Firefox+Selenium+Geckodriver. I'm otherwise following this compatibility table.

What is causing this error and how do I fix it?

Upvotes: 0

Views: 802

Answers (1)

Javier
Javier

Reputation: 151

Root cause could be running out of RAM memory.

To fix it run the docker container adding --shm-size.

Example:

 --shm-size="2G"

Upvotes: 1

Related Questions