TL;DR
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
Output:
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:
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.
Dockerfile
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.
docker-compose.yml
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:
- docker-compose run web bash
- cd ~
- touch text.txt
- exit
- docker-compose run web bash
- ls -al ~
There is no text.txt file!
Here is composer reference documentation.
Here are instructions how to start testing using headless chrome:
- in docker-composer.yml, replace {project_name} with name of your ui automation project folder name.
- copy Dockerfile, docker-entrypoint.sh and docker-composer.yml to your ui automation project folder.
- start docker terminal, cd to ui automation project folder.
- run docker-compose build –force-rm
- 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!