Create a Headless firefox docker image

1 min


638
638 points
firefox docker image
firefox docker image

Headless firefox docker image

Long time ago I wrote an article how to create a docker image that runs google chrome headless. At that point firefox didn’t had any support for that . Now that has been stable for a while I’ve decided to come up with an article that will allow you to create a firefox docker image.

The image itself is based on ubuntu and because of that is pretty heavy.

# Base the image off of the latest pre-built ruby image
FROM drecom/ubuntu-ruby:2.4.0

# make and switch to the /code directory which will hold the tests

RUN mkdir /code
##RUN adduser --disabled-password --gecos '' newuser
WORKDIR /code
#
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
## Copy credenfials config (specific for zooplapro tests)
ADD config/credentials_automation.yml.examples /code/config/credentials.yml
ADD config/report_portal.yml /code/report_portal.yml
## upgrade to latest version of bundler

#
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 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 apt-get install -y firefox
#
#
RUN wget -O /tmp/chromedriver.zip https://chromedriver.storage.googleapis.com/2.39/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

RUN gem install bundler

RUN bundle install

So in this image you’ve got chromedriver installed as well and even firefox installed , so it’s your choice which one you want to use , maybe both .

How to run firefox headless

This is my setup to  run firefox headless.

# frozen_string_literal: true

module FirefoxSetup
  class << self
    def init
      Capybara.register_driver :firefox do |app|
        client = Selenium::WebDriver::Remote::Http::Default.new
        client.read_timeout = 60
        browser_options = ::Selenium::WebDriver::Firefox::Options.new
        browser_options.args << '--headless'
        browser_options.args << '--window-size=1280,1000'

        if App.browser == 'firefox_headless'
          Capybara::Selenium::Driver.new(
            app,
            browser: :firefox,
            options: browser_options
          )
        else
          Capybara::Selenium::Driver.new(
            app,
            browser: :firefox
          )
        end
      end
    end
  end
end

Happy Testing!


Like it? Share with your friends!

638
638 points

What's Your Reaction?

cute cute
0
cute
scary scary
0
scary
wtf wtf
0
wtf
geek geek
0
geek
WIN WIN
0
WIN
Love Love
0
Love
OMG OMG
0
OMG
Angry Angry
0
Angry
Lol Lol
0
Lol
Test engineer

0 Comments

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

Choose A Format
Trivia quiz
Story