Docker Selenium is highly used by test teams to run their tests in parallel on Selenium Grid. In this article, I will explain to you how to use docker selenium and selenium grid infrastructure to run your tests in parallel. You can also find the system architecture and meaning of selenium grid, docker selenium, and docker network. Let’s get started!

What is Selenium Grid

Selenium Grid is a project created for executing tests on different browsers and operating systems. It has a simple architecture: A hub and one or more nodes. You run your test across the hub and hub distributes the test across different browsers.

docker selenium

Advantages of Selenium Grid:

  • Reduces execution time with distributed testing.
  • Allows cross-browser and platform testing.

Problems of Selenium Grid:

  • Hard to configure (Installing Java, downloading selenium standalone server, installing related browsers and drivers etc.)
  • Hard to manage (testing different versions of different browsers)
  • Resource usage.

What is Docker Selenium?

It uses the same architecture but each component, hub, and nodes, is a separate container.

What are the advantages of Docker Selenium?

  • We got rid of all the dependencies are mentioned above.
  • Does not use system resources like VM’s so it’s lightweight.
  • We can easily manage all the version complexity with docker registry.

Docker Selenium Configuration

To be able to use docker selenium, the first thing you need to do docker installation. If Docker is not already installed on your system, please follow the documentation for installation steps. There are different ways to configure selenium. In this tutorial, I will show the docker network and docker compose methods.

Docker Network

Create a Docker Network

Use docker network create <NETWORK_NAME> command to create a network so that the containers can communicate with each other.

docker selenium tutorial

List networks with docker network ls

docker-selenium

Other networks come with docker installation.

If you notice, I did not provide any parameters while creating the network, so the “bridge” network used by default. There are other network types like Host, Overlay, and Macvlan for different use cases. For example, if you have containers on different Docker hosts, you will need an Overlay network.

You may ask “Why we defined a new bridge network instead of using default bridge driver?” The reason is user-defined bridges have some advantages over the default bridges like providing automatic DNS resolution between containers. If I use default network, I should link the containers explicitly by using “–link” parameter which is legacy.

docker-selenium tutorial

For now, there is no container in our network.

Create a Docker Hub

Use docker run to create a hub.

d: detached mode. Container starts in the background with this command. You don’t see any output from container console.

p: publish port (we bind the port 4444 of the container to 4444 of the docker host)

net: specify which network we add the container

name: specify a name of the container and the last parameter is the image name used when creating the container.

docker compose

What happened under the hood?

selenium docker