1

I need to run selenium-side-runner in docker.I wrote in the dockerfile to install Google Chrome and googledrive. But when the code is executed, the error is as follows:

 WebDriverError: unknown error: Chrome failed to start: exited abnormally.
 (unknown error: DevToolsActivePort file doesn't exist)
 (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
 at Object.throwDecodedError (../../usr/lib/node_modules/selenium-side-runner/node_modules/selenium-webdriver/lib/error.js:550:15)
 at parseHttpResponse (../../usr/lib/node_modules/selenium-side-runner/node_modules/selenium-webdriver/lib/http.js:560:13)
 at Executor.execute (../../usr/lib/node_modules/selenium-side-runner/node_modules/selenium-webdriver/lib/http.js:486:26)

this is my dockerfile

FROM python:3.6-stretch

# install google chrome
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> 
/etc/apt/sources.list.d/google-chrome.list'
RUN apt-get -y update
RUN apt-get install -y google-chrome-stable

# install chromedriver
RUN apt-get install -yqq unzip
RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS 
chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip
RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/

# set display port to avoid crash
ENV DISPLAY=:99

RUN apt-get update
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash
RUN apt-get install -y nodejs
RUN apt-get install -y npm
RUN npm install -g selenium-side-runner

WORKDIR /app

ENTRYPOINT ["/entrypoint.sh"]

this is my code:

for ind, file in enumerate(test_file_list):
    file_path = os.path.join(self.save_path, file)
    start_time = timezone.now()
    result = subprocess.run(
        ['selenium-side-runner', '-c', "goog:chromeOptions.args=[--headless,--nogpu] 
         browserName=chrome",file_path])
    end_time = timezone.now()
    result_code = result.returncode
1

2 Answers 2

5

A hack

Instead of installing a browser by hand, I would recommend using already available images like https://github.com/SeleniumHQ/docker-selenium.

A solution (recommended)

From an architectural point of view, each Docker container should have only one purpose. In your case, the container is responsible for running a browser and tests. That's why I propose to split the solution into two containers:

  • the first container with selenium-side-runner and .side files that will run tests
  • the second container runs a browser

Based on the docs, selenium-side-runner can work with a Selenium Grid.

So, the solution will look like

  1. Prepare Dockerfile that installs selenium-side-runner, adds .side files, and configures an ENTRYPOINT. Here you can also set a default URL to Selenium Grid like selenium-side-runner -w 10 --server http://selenium-browsers:4444/wd/hub where selenium-browsers will be a name of the container with a browser or Selenium Grid.
  2. Build your custom Docker image
  3. Create Docker network with docker network create selenium-tests
  4. Run a browser or Selenium Grid
    • Option 1: a browser. docker run -id --shm-size=2g --network selenium-tests --name selenium-browsers selenium/standalone-chrome:3.141.59-2020040 based on SeleniumHQ/docker-selenium
    • Option 2: Selenium Grid. SeleniumHQ/docker-selenium provides instructions how to do this. Also, you may look at Zalenium or Selenoid that provide additional features as video recordings, test execution preview, etc.
  5. Run your container with docker run -it --network selenium-tests --name my-tests <your custom image>

As both containers are in the same custom network selenium-tests, both containers can communicate through the container names. So, my-tests container can send the requests to selenium-browsers container (see #1 and --server option).

If needed, you can create docker-compose.yaml file later to simplify the usage of the solution.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your reply, I have solved the problem successfully
@McCray how did you make to access your localhost environment from the selenium image?
2

You could use this project, put your .side files in side directory and run docker-composer up

2 Comments

Do you have anyu idea how to make to access your localhost environment from the webdriver image?
I suggest you ask that as a separate question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.