Headless chrome docker image

628 points
headless chrome docker image
headless chrome docker image

Headless chrome docker image

Many of you choose to run selenium tests heedlessly , for that you need a docker image , bellow you can find the headless chrome docker image for a ruby environment.


# Base the image off of the latest pre-built ruby image
FROM ruby:2.4
ENV DEBIAN_FRONTEND noninteractive
# make and switch to the /code directory which will hold the tests

RUN mkdir /code
#RUN adduser --disabled-password --gecos '' newuser

RUN mkdir output && chmod a+w output && mkdir output/logs && mkdir output/rerun

# move over the Gemfile and Gemfile.lock before the rest so that we can cache the installed gems
ADD Gemfile /code/Gemfile
ADD Gemfile.lock /code/Gemfile.lock

# install bundler
RUN gem install bundler -v 1.14.6
# install all the gems specified by the gemfile
RUN bundle install

RUN echo "deb http://dl.google.com/linux/chrome/deb/ stable main" | tee -a /etc/apt/sources.list
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN apt-get update && \
    apt-get -qq -y install iceweasel \
                           libxpm4 libxrender1 libgtk2.0-0 libnss3 libgconf-2-4 \
                           libpango1.0-0 libxss1 libxtst6 fonts-liberation libappindicator1 xdg-utils

RUN apt-get update && apt-get install -y google-chrome-stable

RUN apt-get install -f
RUN apt-get -y install \
               gtk2-engines-pixbuf \
               xfonts-cyrillic xfonts-100dpi xfonts-75dpi xfonts-base xfonts-scalable \
               imagemagick x11-apps zip

RUN wget -O /tmp/chromedriver.zip https://chromedriver.storage.googleapis.com/2.33/chromedriver_linux64.zip
RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/
RUN chmod ugo+rx /usr/local/bin/chromedriver

# copy over the rest of the tests
ADD . /code

To get you started with headless chrome you can read our article hereĀ or for more advanced details you can consult google developer pageĀ .

Build your docker image:

docker build -t headless-chrome-docker-image .

Run your selenium tests using headless chrome

docker run --privileged -v /dev/shm:/dev/shm -i headless-chrome-docker-image cucumber -t @foo -f pretty -f rerun --out output/rerun.txt BROWSER='chrome_headless'

Hope this will help , Happy testing!

Like it? Share with your friends!

628 points
Test engineer


Your email address will not be published. Required fields are marked *

two × 3 =