70
Docker Selenium Grid Setup
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.
So before we set up Selenium Grid with Docker, let's first understand why we even need Selenium Grid in the first place?

We need to run through the following steps to get Selenium Grid setup with Docker -
docker network create grid
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
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 -

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.
Once you do that, you will see something like this below -

📧 Subscribe to my mailing list to get access to more content like this as well as free access to a Private Facebook community
👍 You can follow my content here as well -
...
I love coffees! And, if this post helped you out and you would like to support my work, you can do that by clicking on the button below and buying me a cup of coffee -

You can also support me by liking and sharing this content.
Thanks for reading!
70