Table of contents
1.
Introduction
2.
Uses of Selenium Grid
3.
The Architecture of Selenium Grid
3.1.
Hub
3.2.
Nodes
4.
Setup of Selenium Grid
4.1.
Configuring the Hub
4.2.
Configuring the Nodes
5.
Frequently Asked Questions
5.1.
How are Selenium Grid and Selenium Webdriver different?
5.2.
What is a timeout() in Selenium Grid?
5.3.
What is the format of config file in Selenium Grid?
5.4.
How can we check if Selenium Grid is running or not?
6.
Conclusion
Last Updated: Mar 27, 2024
Easy

Selenium Grid

Author Anjali
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

In this article, we will be discussing a crucial concept related to Selenium Grid. We will be having a brief introduction to the selenium grid and its need. Then we will have a look at the architecture of Selenium Grid in terms of hubs and nodes will also be discussed. After that, we will look for the step-by-step setup of the Selenium Grid. 


Selenium Grid is a feature in Selenium that allows us to run test cases in different machines across different platforms. Control of triggering test cases is on local machines, and when the test cases are triggered, they get automatically executed by the remote machine. Suppose you have 3 test cases. Your local machine runs multiple applications, so you want to run your test cases on a remote machine. Hence, you have to configure the remote server so that all the test cases can be executed there.


Selenium Grid supports distributed test execution. Initially, there is a local machine where you write the test cases and execute them on the same machine. But, in a big organization, you have multiple test cases, and it's not possible to run all the test cases on the same machine. In large organizations, you have numerous servers so that the local machine can distribute the test cases across different machines or servers.


We can also run the test cases in parallel in multiple machines on Selenium Grid.

Uses of Selenium Grid

Selenium Grid should be used when you want to do either one or both of the following:
 

  • Run the tests against different browsers, operating systems, or machines all at the same time. It will ensure that the application we are Testing is fully compatible with the wide range of browser and O.S combinations.
  • Save time in the execution of the test suites. If we set up Selenium Grid to run, say, four tests at a time, we would be able to finish the whole test suite around four times faster.

The Architecture of Selenium Grid

Selenium Grid has Hub and Nodes Architecture.

Hub

  • Hub is the central point into which we load your tests.
  • A grid should have only one hub.
  • Hub can be launched only on a single machine, let's say, a computer whose O.S is Windows 7 and whose browser is Internet Explorer.
  • The machine containing the hub is where tests will be run, but we will see the browser being automated on the node.

Nodes

  • The Nodes are Selenium instances which will execute the tests we loaded on the hub.
  • A grid can have more than one node.
  • The Nodes can be launched on multiple machines with different platforms and browsers.
  • The machines which are running the nodes need not be on the same platform as the hub.

Setup of Selenium Grid

Configuring the Hub

Step 1 − First, download the latest Selenium Server standalone JAR file by clicking on the version.
 

Step 2 − Store the jar file on any of the drives. Open the cmd. Register the hub through cmd. Enter the command java -jar selenium-server-standalone-3.5.3.jar -role hub. Now, this command will treat the machine as a hub.



From the above, we observe that the address of the hub is http://192.168.1.6:4444/grid/register. Here the port number is 4444, where the hub resides, and we need to register the hub with these nodes.



Step 3 - Now click on the 'console' link and then click on the 'view config'. There the config of the hub would be displayed as follows. Till now, we haven't got any nodes, hence we will not be able to see the details of the nodes.


 

Configuring the Nodes

Step 1 − Login to the node (where you would like to execute the scripts) and place the 'selenium-server-standalone-3.5.3' in a folder. We have to point to the selenium-server-standalone JAR while launching the nodes.

Step 2 − Launch Firefox Node using the following below command.

java -jar E:\selenium-server-standalone-3.5.3.jar

-role node -hub http://192.168.1.6:4444/grid/register.

-browser browserName = firefox -port 5555
 

Please note here,

  1. E:\selenium-server-standalone-3.5.3.jar : Location of the Selenium Server Standalone Jar File(on the Node Machine)
  2. http://192.168.1.6:4444: IP Address of the Hub, and 4444 is the port of the Hub
  3. browserName = firefox, which is the parameter to specify the Browser name on Nodes
  4. 5555 = It is the port on which Firefox Node will be running.

 

Step 3 - After executing these commands, come back to the Hub. Navigate to the URL:  http://192.168.1.6:4444, and the Hub will now display the node attached to it.
 

Step 4 - Similarly, we can attach the remaining nodes.

Check this out : Xpath in Selenium

Frequently Asked Questions

How are Selenium Grid and Selenium Webdriver different?

Selenium Grid is part of Selenium to run automated test scripts on different machines and different browsers. In comparison, Selenium Webdriver is a framework where it is used to automate the test scripts where these test scripts could be executed on different browsers. 

 

What is a timeout() in Selenium Grid?

The timeout in seconds is the time before which the hub automatically releases a node which hasn't received any request for more than the specified number of seconds.

 

What is the format of config file in Selenium Grid?

The config file in Selenium Grid is JSON format.

 

How can we check if Selenium Grid is running or not?

By typing http://localhost:4444/grid/console in any web browser and then clicking on the View Config link, which pulls up a detailed configuration window with data that we succeeded in launching a Selenium hub

Conclusion

In this blog, we started with the Selenium Grid introduction. Then we discussed the uses of Selenium Grid. We have also seen the architecture of the selenium grid with the help of hub and nodes. In the end, we had a step-by-step discussion of the setup of the Selenium grid in our machines.
 

We hope that this blog helped you enhance your knowledge in getting started with Selenium Grid and understanding its architecture. Learning never stops, and to learn more and become more skilled, head over to our practice platform Coding Ninjas Studio, to practice top problems attempt Mock Tests, read informative blogs, and interview experiences. Do upvote our blog to help other ninjas grow. 
 

Happy Learning!

Live masterclass