Home > front end >  Running Selenium on python:3.7 Container
Running Selenium on python:3.7 Container

Time:10-24

I am trying to run a Selenium script using the base python:3.7 image, but I am a little unsure as to how to install the required dependencies. I have come across several other questions about using different images like selenium/standalone-chrome, however, I have several other scripts that do not use Selenium running on this container, so I am a little hesitant to change it.

Is it possible for me to run Selenium on this image? Or if I change it to selenium/standalone-chrome will it affect the rest of my application. I am running a flask API.

This is the error that I am faced with right now,

selenium.common.exceptions.WebDriverException: Message: Service <path>  unexpectedly exited. Status code was: 127

Note that I have only pip installed selenium and not the other dependencies like chrome.

CodePudding user response:

The proper use-case would be to have selenium/standalone-chrome container running and separately to have a container that runs the test code.

Having that you run your "cluster" with docker-compose and your test refer to remote selenium container with the help of `RemoteWebDriver'.

CodePudding user response:

I was able to find what I needed here, https://dev.to/nazliander/using-selenium-within-a-docker-container-ghp

The following commands can be added to your Dockerfile in order to install Chrome Driver for running Selenium,

# Adding trusting keys to apt for repositories
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
# Adding Google Chrome to the repositories
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
# Updating apt to see and install Google Chrome
RUN apt-get -y update
# Install Google Chrome
RUN apt-get install -y google-chrome-stable
# Installing Unzip
RUN apt-get install -yqq unzip
# Download the Chrome Driver
RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip
# Unzip the Chrome Driver into /usr/local/bin directory
RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/
# Set display port as an environment variable
ENV DISPLAY=:99

Note that this worked on the python:3.7 base image that I have been using.

  • Related