Semi-Headless (Remote) Chrome and Firefox for Running Selenium Testing using Docker

For running selenium testing, of course we need web browser. If you don’t require a real browser PhantomJS might be enough for you. But if you need real browser (Chrome, Firefox, etc…) — in my case, need two real browser running side by side for simulate chatting — instead of running it in your local machine, I have alternative solution to dockerize it. I propose you to dockerize real browser (Firefox and Chrome) on your remote server (it can be your local docker machine or your cloud server), so we can access it remotely. How to do it is very simple, you just need follow this instructions.

Pre-Requisites

You need the last version of Docker and docker-compose and also in the release candidates. To figure out the currently used specific versions it surely works on:

docker --version         #=> 1.12.0
docker-compose --version #=> 1.8.0

If you need to use docker-machine to run docker (like for example on a Mac before the Docker native version 1.12), you also need to install VirtualBox and then run these commands to get started:

docker-machine create --driver virtualbox default
eval "$(docker-machine env default)"

After that you need to create docker-compose file to create docker container for remote browser on your remote server:

docker-compose.yml

After your docker compose file ready, next step is to create shell script for run the docker-compose. Here is the example shell script for running the docker-compose file.

docker shell script

If you don’t want to create shell script for run docker-compose. You can run docker command to run your docker compose on your remote server:

docker-compose up -d

If you choose to create shell script for run docker-compose, you need to run this command on your remote server:

./docker.sh

After docker-compose command successfully executed, you need to verify the docker containers using this command on your remote server:

docker ps -a

You may see all docker containers for remote browser is up.

Docker Container selenium, firefox, and chrome

After that, you just need to check is selenium and your remote browser already running by entering this url:

{Your Remote IP}:{Selenium Port}/grid/console
Selenium grid console

Congratulation, your remote browser successfully installed and already running.

For use remote browser on your selenium testing, you just need to replace the selenium address and selenium port with the installed selenium address and port on docker.

Sample usage remote browser on python selenium:

sample usage remote browser on python selenium

Next posting, I will give an example running selenium testing on python using behave and remote browser.

Happy Testing!

Source:

https://github.com/elgalu/docker-selenium