All Solution Projects

Docker Selenium Codeception Jenkins Container

This is a description and an installation/configuration manual for our Docker Selenium Codeception Jenkins container. Following it and using the code snippets below will help you deploy all the Codeception testing ecosystem 30 times faster, in 10 minutes instead of several hours. You won’t worry about versions compatibility, as well as have the flexibility of choosing between browsers. Google Chrome and Mozilla Firefox are included with corresponding web drivers.

Provisioning a Selenium/Codeception testing environment: 8 hours of hard work

We faced the same problem many DevOps engineers worldwide have to deal with: Codeception is a great solution for automated testing, yet provisioning the software ecosystem needed to work with it is a pain in the back. Keeping in mind all the needed packages and their correct versions, installing and configuring all the components was actually the monkey’s work that took up to 8 hours sometimes, if any issues occurred. They did occur quite often, so we decided to eliminate the problem once and for all. A Docker container with pre-installed Jenkins, Codeception, Selenium, Google Chrome, Mozilla Firefox and the appropriate WebDrivers was the obvious solution.


Automation and ease of deployment: a Docker Selenium Codeception Jenkins container

We want to receive the following improvements and benefits with this container:

  • A stable solution for rapid deployment of Codeception testing environments
  • Automation and ease of deployment due to error-proof step-by-step script
  • Ease or reproducibility to ensure the same results of the tests run by multiple testers, to avoid the “works on my machine” situation.

We had our share of experimenting and errors, yet the resulting container is able to solve all the issues mentioned above.

Preparing a Docker container: Dockerfile for installing the components

Below we will provide a step-by-step sequence of actions needed to create the Dockerfile and run the Selenium Codeception container easily, along with some explanations.

  1. Begin preparing the image with having only bare Jenkins installed onto it:
    FROM Jenkins
  2. Change the user to root in order to be able to work with Selenium without any issues later on:
    USER root
  3. Install X Virtual Framebuilder and PHP5 with the required modules:
    RUN apt-get update
    #install PHP xvfb
    RUN apt-get install -y php5 php5-curl php5-gd xvfb
  4. Install Selenium next:
    # Install Selenium
    RUN mkdir -p /opt/selenium
    RUN wget --no-verbose -O /opt/selenium/selenium-server-standalone-2.53.1.jar
    RUN chmod +x /opt/selenium/selenium-server-standalone-2.53.1.jar
  5. Install the Chrome WebDriver:
    # Install Chrome WebDriver
    RUN wget --no-verbose -O /tmp/
    RUN mkdir -p /opt/chromedriver-2.28
    RUN unzip /tmp/ -d /opt/chromedriver-2.28
    RUN chmod +x /opt/chromedriver-2.28/chromedriver
    RUN rm /tmp/
    RUN ln -fs /opt/chromedriver-2.28/chromedriver /opt/selenium/chromedriver
  6. Install a clean Google Chrome:
    # Install Google Chrome
    RUN wget -q -O - | apt-key add -
    RUN echo "deb stable main" >> /etc/apt/sources.list.d/google-chrome.list
    RUN apt-get -y update
    RUN apt-get -y install google-chrome-stable
  7. Disable the Google Sandbox in order to fix the compatibility of Google Chrome with Selenium. If sanbox is enabled, Selenium can’t start doing tests via Google Chrome. This is actually quite a dirty lifehack making your life a ton easier, as the issue just won’t be fixed by the Selenium team:
    # Google Chrome -- no sandbox
    COPY google-chrome /opt/google/chrome/
    RUN chmod +x /opt/google/chrome/google-chrome
  8. Install composer for downloading the PHP modules:
    # Install composer
    RUN curl -sS | php -- \
    --filename=composer \
    RUN composer global require --optimize-autoloader \
    RUN php -v
  9. Install Firefox:
    # Install the FireFox
    RUN touch /etc/apt/sources.list.d/debian-mozilla.list
    RUN echo "deb jessie-backports firefox-release" > /etc/apt/sources.list.d/debian-mozilla.list
    RUN wget
    RUN dpkg -i pkg-mozilla-archive-keyring_1.1_all.deb
    RUN apt-get update
    RUN apt-get install -y firefox
  10. Install Codeception:
    # Install Codeception
    RUN touch /usr/local/bin/codecept
    RUN curl -o /usr/local/bin/codecept
    RUN chmod +x /usr/local/bin/codecept
    #RUN php codecept.phar bootstrap
  11. Copy the script and issue the run command:
    # ADD
    COPY /usr/local/bin
    ENTRYPOINT ["/bin/bash"]
    CMD ["/usr/local/bin/"]

The image is ready now, so save it for further usage and let’s move on! script explanation

The script launches the previously built container, complete with Selenium and Google WebDriver.

  1. Launching the X Virtual Framebuilder
  2. Launching Selenium
    java -jar /opt/selenium/selenium-server-standalone-2.53.1.jar
  3. Launching the chromedriver to act as an API bridge between Selenium and Chrome:
  4. Suppressing the stdout and stderr to remove the unneeded output:
  5. Add & to launch the container in the background and avoid blocking the CLI:
  6. Launching Jenkins:
    /bin/tini -- /usr/local/bin/

The full script looks as follows and can be adjusted with appropriate browser driver should you so desire:


xvfb-run java -jar /opt/selenium/selenium-server-standalone-2.53.1.jar &>/dev/null &
/bin/tini -- /usr/local/bin/

The progress so far

This tool allows shortening the testing environment deployment time more than 30x times, to 10 minutes.

We are working to implement the following features:

  • Safari WebDriver support for Selenium
  • A supervisor with Process ID’s to use Jenkins for swift manipulation of multiple testing environments and separate outputs for Jenkins.log and Selenium.log
  • Having Jenkins container untouched and using Jenkins worker for it.

The repo also contains the stable combination of Chrome WebDriver, Selenium and Google Chrome packages for your convenience. Clone it, as you will surely want to poke around and play with the container to better suit it to your unique requirements! Good luck, and if you need any more assistance — don’t hesitate to drop us a line!

©IT Svit 2019 All rights reserved

Terms of Service Privacy Policy