SDET Unicorns

Docker Selenium Grid Setup

Table of Content

In this tutorial, we will cover how to set up Selenium Grid with Docker and also go over why we should use Selenium Grid. We will also increase max instances and max sessions for the Selenium Grid in Docker to run tests in parallel.

Why do we need Selenium Grid?

So before we set up Selenium Grid with Docker, let’s first understand why we even need Selenium Grid in the first place? 

  • Multiple browsers/devices: Grid makes it much easier for us to run tests on multiple browsers/devices 
  • Test execution time: You can reduce overall test execution time by running tests in parallel in Grid
  • Infrastructure: Setting up the infrastructure to run tests on multiple browsers/devices on different OS is also possible to do with the help of Grid
0*oBGnOy5 QXeic1Z1
Selenium Grid

Setting up Selenium Grid with Docker

We need to run through the following steps to get Selenium Grid setup with Docker — 

  • Setup a network (grid) to communicate between images
docker network create grid
  • Run selenium/hub docker image for running a Selenium Hub
docker run -d -p 4444:4444 --net grid --name selenium-hub selenium/hub:3.141.59–20210422

Note: the network name (grid) should be the same as what you provided when creating the network

  • Run Chrome & Firefox images connecting with grid network & selenium/hub host
docker run -d --net grid -e HUB_HOST=selenium-hub -v /dev/shm:/dev/shm selenium/node-chrome-debug:3.141.59–20210422
docker run -d --net grid -e HUB_HOST=selenium-hub -v /dev/shm:/dev/shm selenium/node-firefox-debug:3.141.59–20210422

Note: the network name (grid) should be the same as what you provided when creating the network and the HUB_HOST name (selenium-hub) should be the same as what you provided when running the selenium/hub docker image

Now, head over to port 4444 and you should see Grid setup with Chrome and Firefox — 

0*HGDnnhIp2HYjUG5K
Selenium Grid with Chrome & Firefox

Increasing the MAX_INSTANCES & MAX_SESSIONS for the Grid

So far we just have 1 instance of Chrome & Firefox, however, if you need to run multiple tests together, you’ll need more instances spun up. You can do that quite easily by adding the parameters when running the docker container for Chrome and Firefox.

docker run -d --net grid -e HUB_HOST=selenium-hub -e NODE_MAX_INSTANCES=3 -e NODE_MAX_SESSION=3  -v /dev/shm:/dev/shm selenium/node-chrome-debug:3.141.59–20210422

You can pass NODE_MAX_INSTANCES and NODE_MAX_SESSION environment variables to add multiple instances of the browsers. 

NODE_MAX_INSTANCES: number of instances of the same version of the browser

NODE_MAX_SESSION: number of browsers (any versions) that can run in parallel

Once you do that, you will see something like this below — 

1*FR2uPcnCgrzRjN8NFWJUMA
Selenium Grid with max instances & max sessions

Check out the video below to learn more about how to setup Selenium Grid with Docker –

In the next tutorial, I will show you how to set up Selenium Grid with Docker compose.

Thanks for reading.

My Resources

Thrive Suite: The all-in-one WordPress theme I used to create my blog.
Jasper AI: My favorite AI writing tool.
Surfer SEO:  A tool to help you rank your content on the first page of Google.

Write Content Faster

5/5

Write blog posts that rank for affiliate terms!

Join our mailing list

Unlock the Secrets to Becoming a SDET Pro in the Industry!

Stay ahead of the curve! Join our mailing list for exclusive insights, tips, and the latest industry updates delivered straight to your inbox

Table of Content

Related Post

Differences Between CI/CD and DevOps

Key Differences Between CI/CD and DevOps

Software development is far from a simple journey that involves merely executing code and launching applications. It often presents challenges, as it’s rare to get everything right from the start. Each time you implement new or frequent code changes, you inadvertently introduce potential issues that can be time-consuming to resolve. This complexity necessitates a structured approach to ensure smooth production.

Read More »
image

Common Types of Software Bugs

Dealing with bugs is one of the biggest headaches in the software development lifecycle. No matter how carefully someone writes code, it’s impossible to create a software product that works perfectly every time. Skipping detailed testing often causes major issues later on.

Read More »