Docker Selenium Tutorial: How to Integrate Selenium Grid with Docker

Introduction to Docker Selenium Tutorial:

As discussed in one of our previous tutorial Selenium grid helps to run our test cases in different operating systems and on different browsers.

However, this Docker Selenium Tutorial will explain to you more about what a Docker is and how we download, install, and integrate it with the Selenium grid along with concerned screenshots and this pictorial representation will enable you to understand the process quickly and easily too.

Docker Selenium Grid

What is Selenium Grid?

Selenium grid helps to master the computer (hub) to distributed test cases among the slave machines (nodes).

When we implement all the test cases in one machine at some point there might be some limitations, and sometimes one single machine will not be sufficient enough to run all the test cases and that point of time Selenium grid comes into the role.

One Practical Example of Usage of Selenium Grid

2-3 years ago China banned Google products in the country. At that time some other companies who developed web systems for China had to test their web system with different browsers except Google products (Google Chrome) such as Internet Explorer, Firefox, Opera, etc.

So at that time Selenium grid was very useful to those companies, as they used the Selenium grid for running their test cases in different browsers except Google Chrome.

What is Docker?

In simple terms, Docker can be termed as a container. Developers or Docker users can put things like database, libraries, dependencies into that container, and then use those databases, dependencies, and libraries to create, deploy, and run applications.

By using Docker containers you can set up and pack a software application with all of the contents that are required to build that application, such as databases, libraries, and other dependencies, and finally, you can ship them all out as one package.

Usually while configuring the Selenium grid we need to host multiple virtual machines as nodes and we need to connect every single node with the hub. Also, when we set up a normal grid we need to download the Selenium server jar file and run that jar file on each computer in which we are going to set up the Selenium grid.

This is costly and sometimes a time-consuming task for the testers. However, Docker helps us to solve cost-related and time-consuming problems.

Docker was invented by Solomon Hykey and was launched into the software industry in 2013 March as an open-source tool. Nowadays, developers and system engineers are using Docker for several reasons.

In this tutorial, we are going to use Docker for software testing and software automation.


Pre-requisites for Docker Selenium Tutorial

First of all, we need to set up an environment to run the Selenium script.

Given below are a few things we need to check:

  • If your machine consists of JDK 1.7  or later version
  • Is Chrome and Firefox browsers installed on your local machine?
  • Selenium WebDriver and TestNG based test cases.
  • Configured Testng.xml file to run test cases as parallel tests.

Downloading Docker for Windows

The next thing that we need to do is to install the Docker toolbox. To run Docker commands, we need Docker quick start terminal which will come along with the Docker toolbox. Hence we have to install the Docker toolbox.

We can download the Docker toolbox from any website but, I would highly recommend you download the Docker toolbox from their official website: Docker.

While installing the Docker toolbox, a few checkboxes will appear, and to complete the installation, you need to check all those checkboxes and install Docker toolbox. If you have installed it successfully, then you will get the following three Docker toolbox icons.

Downloading Docker

After installing the Docker toolbox double-click and open the Docker quickstart terminal. Docker will configure your default machine with the IP Address: and it will take some time to configure your local machine for the first time. Hence you have to wait until the following window appears.

appear window

Docker is configured successfully!

Install the Docker Images

While we configure the Selenium grid (without Docker), we also need to configure Selenium hub and nodes (browsers).

Like a normal grid when we configure the Selenium grid with the Docker we have to install the hub and browser nodes into our Docker container and later, we can start the hub and nodes from that Docker container.

Hence the first thing is to install the hub and node images into the Docker.

Initially, we need to install five images to run our test using Docker.

  • Selenium hub image
  • Selenium node-firefox image
  • Selenium node-chrome image
  • Selenium node-firefox-debug image
  • Selenium node-chrome-debug image

The next question will be, how to find those images. To find those images we move on to the Docker Hub and search those images by name and you can also type the image name in the search bar as shown below.

docker hub

Once you type the name and hit enter, you will be able to see the below window.

A window

This window shows all the image repositories that we have for Selenium hub. Here you need to click the image that has the most number of pulls and it will help to run our code without any errors. Once you click on that image you will see another window like the one given below.

(Note: Click on any image for an enlarged view)

After clicking on the image

This window will provide you with all the information about the image (Selenium hub image) and will give you all the commands relevant to that image (Selenium hub image). Here, the Docker pull command is the command to install that Docker image to your container.

Hence initially, we have to install the Selenium hub image. To do that you need to copy the Docker pull command and paste it into the Docker quick start terminal as shown below.

install selenium hub image

After entering each command into the Docker quick start terminal, you need to wait for some time to allow the images to download into your Docker container and the wait time completely depends upon the speed of your network connection. Sometimes some images will fail while installing or downloading and if it happens so then the best thing to do is to install that image again till the terminal shows as installation completed.

Another important factor is one should not type the second command before completing the download of the first command. It will fail both the download and the installation.

Likewise, you can search and install all the five images mentioned above in your Docker container.

The below table shows all the pull commands that you need to type into the Quickstart terminal and install.

Selenium hubdocker pull selenium/hub
Selenium firefox nodedocker pull selenium/node-firefox
Selenium chrome nodedocker pull selenium/node-chrome
Selenium firefox debugdocker pull selenium/node-firefox-debug
Selenium chrome debugdocker pull selenium/node-chrome-debug

After downloading all the images into your container you can check it using the below command.

Docker Images

docker images

Now all the images are downloaded successfully. Hence we can run those images one by one.

Start Selenium Hub

In a normal Selenium grid (without Docker) the first step is to start Selenium hub. To start Selenium hub from Docker container, we have a special command which is

docker run -d -p 4444:4444 –name selenium-hub selenium/hub

docker run command

Once you type and enter that command in your terminal, the Selenium hub will be open from the Docker container. You can verify whether Selenium hub has started or not by checking the following link in your browser:

link in browser

Here in this image is your IP address

Start Selenium Nodes

Selenium hub is started and next, we need to start nodes from Docker container, we need to start chrome node and Firefox node. We have installed both the node images into our Docker container in the installation process.

Now, let’s start with both the nodes one by one. Also, remember that you can run as many nodes as you wish. Here I have used two nodes only (chrome node and Firefox node).

Command to run chrome node from Docker: docker run -d –link selenium-hub:hub selenium/node-chrome

Command to run firefox node from Docker: docker run -d –link selenium-hub:hub selenium/node-firefox


After running Chrome node and Firefox node, we need to run Chrome debug node and Firefox debug node as well. We run and install the chrome debug node and Firefox debug node for demonstration purposes and at the end of this tutorial, I will run a test case in both the debug nodes by using VNC (Virtual Network Computing) viewer.

For VNC viewer we need both the debug node of firefox and chrome. VNC (Virtual Network Computing) viewer helps us to view different browser actions at the same time on one computer.

Command to run chrome debug node from Docker: docker run -d –P –link selenium-hub:hub selenium/node-chrome-debug

Command to run Firefox debug node from Docker: docker run -d –P –link selenium-hub:hub selenium/node-firefox-debug

Sometimes both the commands may be ignored by the Docker quick start terminal. If your Docker quick start terminal ignores those two commands then alternatively you can use the below commands to start the debug mode of chrome and Firefox browsers.

Alternative 01

docker run –d –P –link selenium-hub:hub selenium/node-chrome-debug

docker run –d –P –link selenium-hub:hub selenium/node-firefox-debug

Alternative 02

docker run –d –link selenium-hub:hub selenium/node-chrome-debug

docker run –d –link selenium-hub:hub selenium/node-firefox-debug


After running both the nodes and debug nodes of Chrome and Firefox nodes and chrome and Firefox you can refresh your browser and you will find Firefox and chrome node starting from your container.

Firefox and chrome node

If any error occurs during the installation or running process of images, the best thing to do is to re-install and run that particular image again from Docker.

We have now completed all the steps in the Docker container side. Next, we need to give attention to the Selenium script and VNC viewer for doing our demonstration.

Firstly, we need to identify the port numbers of chrome and firefox debug nodes that are running. Because we require those port numbers for VNC viewer.

To identify the port numbers of chrome and Firefox node, you can type the below command in your quick start terminal and you will able to see all the Docker images and the running ports of each image under the PORTS column.

docker ps –a

PORTS column

NodesRunning Port Numbers
Chrome debug node32771
Firefox debug node32772

Now, we know the port numbers of chrome and firefox debug nodes that are running so we can start both the browsers using VNC viewer.

For that we need to follow the steps given below:

1) Download VNC viewer from their official site: Download VNC

2) Run it

3) Type the hub URL and the port number of each debug mode as shown below and click on the connect button


  • For Chrome browser


4) After clicking on the connect button VNC viewer will ask for a password. By default the password for VNC viewer is secret, type the password as secret and click Ok and you will be able to see a window for the chrome browser.

5) Likewise, you have to do the same for the Firefox browser by using a VNC viewer. Open the VNC application on your local computer and use Firefox running port number with the hub URL and click the connect button.

  • For Firefox browser

Again you will see another window opening for the Firefox browser.

Firefox browser

Now both the browsers are shown up in the VNC viewer. Our next task is to write the selenium script and run it.

Configuring Selenium Tests

As usual, we can create a test script that is relevant to the selenium grid, steps to create a selenium grid script is discussed in our selenium grid tutorial.

Here is the script that I created, this is a normal selenium script and I created two tests and have set the desired capability of those tests to two different browsers which we created.

two different browsers created

Also, I changed my XML file to run the test in a parallel way.

test parallel way

We have completed all the steps and you can run your test now. After running your test, you will be able to see the test running through two different browsers that we created using Docker.  VNC viewer will show how a browser navigates to each website at the same time.

browser navigates


When you have a large number of test cases, you can use the Selenium grid for speeding up your test case executions. Sometimes we have to run and test your test cases under different operating systems and at times you have to check your test cases under different browsers as well. We use the Selenium grid under such occasions.

At times configuring the Selenium grid might be a high-cost involving and time-consuming process as we need multiple machines. Under such cases, the best option will be to use the Selenium Grid with Docker.

Related Post

Leave a Reply

Your email address will not be published.