Configure selenium grid on docker:
In this article, I am trying to showcase how to configure a Selenium Grid setup on Docker Containers and eventually it will help the new learners who are going to configure their automation setup in containers.
What is Selenium Grid?
Selenium grid is a part of selenium suite which uses a hub-node concept where the test will run on a single machine called HUB , but the execution will be done by a different machine called nodes.
When to use Selenium Grid?
You can use Selenium grid if you want to do either one or both of the following:
- Running your tests against different browsers, operating system, and machines all at the same time. Which will ensure that the application you are testing is fully compatible with a wide range of browser-OS combinations.
- Save the execution time of your test suite. Eg; If you run 4 test cases at the same time in selenium grid. Then you will be able to finish the whole suite 4 times faster
How to Configure the Grid and Register multiple Nodes?
Step 1: Create 2 docker containers(CentOS Linux 7) with exposed ports-
- For Selenium grid HUB-
$sudo docker run -d -p 2020:5901 -p 1010:6901 -p 4445:4445 -p 5558:5558 --name gridserver -h gridserver <ImageName>
- First Selenium grid node-
$sudo docker run -d -p 3030:5901 -p 4040:6901 --name gridnode -h gridnode <ImageName>
Step 2: Download the Selenium Server Standalone jar from - https://www.seleniumhq.org/download/ and execute it inside the containers to bring up the HUB and Node setup.
- For HUB -
$java –jar <jarname> -role hub –port 4445
And the grid server is accessible through the browser but there is no node available here-
- For NODE to register with server -
$java –jar <jarname> -role node –hub http://<GridServerName>:4445/grid/register
And the grid setup is complete once the hub got registered with the server, and the node is also available here.
So now we are good to go with our selenium tests and execute it on that node container machine.