Headless browser testing in docker container

Reading Time: 2 minutes


In this post you will find out how to run headless chrome browser tests on your development machine using prepared and configured docker machine.

Docker enables you to run on your development machine minimal linux machine. You are in control which software will be installed in that linux machine. All linux machine configuration is stored in two files. Docker uses cache, so only changes in machine configuration are rerun.

Install Docker

First, you need to install Docker for your operating system. Fire up docker terminal after you installed it.

Type: docker-machine ls


Screen Shot 2016-02-14 at 11.11.42 AM


docker machine is linux (special docker flavour), that has docker software that will run your docker containers. It runs in virtualbox that is automatically installed with docker.

You can ssh to it:


Screen Shot 2016-02-14 at 11.19.15 AM


Clone this github repository that contains docker files needed for creating and running docker image. Follow the README instructions. And that it is, you can run headless chrome tests on your development machine. While those tests are running, you can use your development machine for other tasks.


Here is official Dockerfile reference documentation. Dockerfile is source code for creating docker images. But I would like to save you time that I spent investigating the official documentation, so you will be ready to create your own docker images very quickly.

Important note: in order to be able to create your own docker images, previously you have successfully configured and installed linux, connected to linux machine, and you know your way around in linux shell.

You do not have to create Dockerfile from scratch. There is great Dockerfile repository, called Docker hub. In search box input what you need, e.g headless chrome, and there is high probability that somebody already have prepared what you are looking for.

If this is not the case, you can download Dockerfile and change it according to your needs. Check in Dockerfile reference what every docker command actually do.


This is second file from docker ecosystem. It is a source code for creating docker containers and their interconnections based on docker machines. For example, WordPress site needs (according to good architecture practice) php container and mysql container.

Line 4 in docker-compose.yml maps current directory (your ui automation project folder) to web docker container app folder. That is the magic which enables docker to run your cucumber tests in docker linux container that is ready with headless chrome, something that is not possible on osx.

Volumes are important docker feature, because without them, docker container does not remember any changes.

Additional magic is that bundle install is run on docker-compose build only when Gemfile is changed.

For example:

  1. docker-compose run web bash
  2. cd ~
  3. touch text.txt
  4. exit
  5. docker-compose run web bash
  6. ls -al ~

There is no text.txt file!

Here is composer reference documentation.

Here are instructions how to start testing using headless chrome:

  1. in docker-composer.yml, replace {project_name} with name of your ui automation project folder name.
  2. copy Dockerfile, docker-entrypoint.sh and docker-composer.yml to your ui automation project folder.
  3. start docker terminal, cd to ui automation project folder.
  4. run docker-compose build –force-rm
  5. run your tests: docker-compose run web /bundle/bin/cucumber -f html -o chrome.html features/feature_name.feature

chrome.html file is created in your local folder, in root folder of ui automation repository!


Facebooktwittergoogle_plusredditpinterestlinkedinmailby feather

Karlo Smid


Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.