How to setup Docker for Selenium automation

Why docker? What is benefit of docker for selenium automation?

Docker containers are lightweight packages of all the necessary components (application code, dependent libraries, specific versions of programs) to run the application over any platform. To run and manage these containers in a standard and efficient way is a challenge.

Dockers helps setting up test environments easier and faster with all OS-browser combinations. with use of dockers we can bring up and down test environment as and when required. Another advantage is running parallel test with use of docker containers in single server.

Steps to install and configure docker for Selenium automation

Step 1 – Install docker for windows from following location.

During installation, select ‘Enable Hyper-V Windows Features’ option on the configuration page.

Note: if you are logged in with non admin user then add the user to docker-user group from computer management. To do so, run Computer Management as an administrator and navigate to Local Users and Groups > Groups > docker-users.

Step 2 – Once installed, launch docker desktop.

To check that docker is set up properly run the following command in Command Prompt. It returns the version of docker installed on the system.
docker –version

Step 2 – Build images for Selenium Hub and browser nodes

Once the setup is done, you can either create a Docker image from scratch or pull an already configured base image from the Docker hub and then add on to it.

Run the following command to pull the docker images

docker images

If you do not already have the selenium standalone-chrome docker image, run the following command to download a copy of the image onto the system.

docker pull selenium/hub

docker pull selenium/standalone-chrome

Refer this link for more images –

After pulling the images check the images using command – docker images

Step 3 – Create containers by running Selenium hub and node in specific ports

docker run -d -p 4444.4444 –name selenium-hub selenium/hub

docker run -d -p 5900.5900 –link selenium-hub:hub -v /dev/shm:/dev/shm selenium/node-chrome

Note- if the image is not available it will pull automatically as shown above.

Check the if the container is created using command – docker ps

In the above example hub port is https://localhost:4444

Connecting to node using vnc viewer as shown below. Note the default password is ‘secret’

That’s all for this post. In the next post we will see how to use it with sample test. Also will deep dive in different way to create docker container and run them on demand.

Leave a Reply

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