Business organizations across the world are continuously involved in the pursuit of delivering better and more sophisticated versions of software applications. This is important in order to invite more and more engagement. However, in order to realize this process of software deployment within short periods of time; Automation Testing has become indispensable. In this respect, Selenium has evolved as one of the most versatile Test Automation Tools of choice. Moreover, rather than being a standalone tool, Selenium provides a suite of tools, each of which is suited for a specific purpose. In this respect, Selenium Grid has emerged as one of the prominent components of the Selenium suite and questions about what is Selenium Grid has become a popular query within tech and non-tech circles alike.

In this blog, we shall try and answer the question of what is Selenium Grid. We shall look at different versions of Selenium Grid like Selenium Grid 2.0 as well as Selenium Grid 4. We shall try and understand the idea of Selenium Grid Architecture. We shall discuss the entire process of Selenium Grid download as well as Selenium Grid setup. Consequently, we shall also try to make sense of the Selenium Grid Docker. 

What is Selenium Grid?

Selenium Grid 2.0

Selenium Grid 4

Selenium Grid Architecture

Download Selenium Grid

Selenium Grid Setup

Docker Selenium Grid

Conclusion

What is Selenium Grid?

Selenium Grid is an important component within the Selenium suite of tools which facilitates simultaneous execution of multiple tests across different operating systems, browsers as well as machines. In this entire Selenium Grid Architecture, one of the servers  act as the hub and is responsible for routing commands to remote web browsers. This implies that the control for the regulation and triggering of the test cases is with the local machine and once it is initiated, it is executed by the remote machine. Thus, an individual is required to configure the remote server in order to run the tests.

selenium suite of tools

So what is Selenium Grid in simple words? Selenium Grid is a useful tool based on the principle of hub-node. This implies that a user is required to run the test only on a single machine which is referred to as the hub and the execution of the test cases takes place in different machines, in parallel. For instance, you want to run 7 test cases. However, your local machine happens to be occupied with multiple applications. Selenium Grid facilitates the execution of your test cases in remote machines. You are just required to configure the remote server. 

Selenium Grid 2.0

Selenium Grid 2.0 has been considered to be an improvisation over and is fundamentally different from Selenium Grid 1. While Selenium Grid made use of RC; Selenium Grid 2.0 was dependent on WebDriver. Moreover, Selenium Grid 2.0 came bundled with Selenium Server jar file and did not entail the requirement of installation of Apache Ant. It supported Selenium RC as well as WebDriver scripts and facilitated the automation of 5 browsers through one remote control. 

Selenium Grid 4

Selenium Grid 4 is considered to be a fresh addition in the chain of Selenium Grid tools. It is important to note that Selenium Grid 4 does not share the codebase of the previous versions and instead of 2, it supports four distinct processes in the form of: Router, Node, Distributor and Session Map. Moreover, Selenium Grid 4 supports four grid types too. This includes:

  • Standalone Mode
  • Fully Distributed (Router, Distributor, Node and Session)
  • Classical Grid (Hub and Node)

Selenium Grid 4 also offers docker support and is quite easy to be used on virtual machines. 

Selenium Grid Architecture

The Selenium Grid Architecture refers to the components of the Selenium Grid framework. This primarily includes two parts. 

The Hub

  • It is the central point which facilitates the loading of the tests. 
  • It is the central machine which actually triggers the test cases in the remote ones. 
  • It receives all the test requests and distributes them to the right nodes. 
  • It accepts the access requests from the WebDriver client. 
  • In a grid, there is only one hub. 
  • The machine which contains the hub is the point which provides for the running of the tests. But the browser is automated on the node. 
  • The hub is launched on a single machine. For instance, it can be launched on a computer whose O.S is Windows 7 and whose browser is IE.
Selenium Grid Architecture

The Node

  • It is the remote device which consists of the remote WebDriver and native OS. 
  • It is the one which receives requests from the hub in the form of JSON commands. 
  • They are Selenium instances which are responsible for the execution of the test cases loaded on the hub. 
  • While there can be a single hub, there can be multiple nodes. 
  • Since nodes are launched in multiple machines, they can have different platforms and browsers, which may not necessarily be same as that of the hub. 

Download Selenium Grid

In this section, we shall consider the issue of Selenium Grid download. This will include the topic of Selenium Grid setup for the hub as well as the nodes. The Selenium Grid download and setup will be discussed with reference to two machines. One of the machines (Machine A) will run the hub, while the other machine (Machine B) will run the node. The Selenium Grid setup on both the machines entails the requirement of executing certain commands. Moreover, we also do have to take into account the IP addresses of the two machines. For our purpose of convenience, let’s say, the IP address of Machine A is 192.168.2.3 and that of Machine B is 192.168.2.4. 

In the first step you need to proceed with the process of downloading Selenium Grid. 

  • Selenium Grid comes built into the Selenium Standalone Server. Hence, we will be required to download the latest version of it from, http://docs.seleniumhq.org/download/
  • Once the jar file has been downloaded, you will be required to place it in an appropriate dictionary. Let us assume that we have placed it in a Selenium folder in C drive. 

Selenium Grid Setup

In this section we shall look at the process of configuring hub as well as the node. 

Hub Set up

  • In order to proceed with this setup, you need to proceed to the hub machine, i.e., Machine A. You need to open the command prompt and navigate to the directory where you would have saved the Selenium Grid Server. 
  • Next, on the command prompt, you will be required to enter the following command:

java -jar selenium-server-standalone-<version>.jar -role hub

  • By doing so, the hub is launched successfully. 

Hub Console Launch

In order to verify whether the hub which has just been setup is running successfully or not; one can take the help of a browser. By default, Selenium Grid would use port 4444 of Machine A for its web interface. Accordingly, you can open a browser and go to:

https://localhost:4444/grid/console 

Moreover, if you want to check whether the other would be able to access the web interface of Machine A or not, you can send the same command in the browser. Only this time, you will be required to replace the <localhost> in the command with the IP address of Machine A. 

Node Setup

  • Once again, you have to navigate to the directory where the Selenium server is placed. Then you have to type the following command:

java -jar selenium-server-standalone-<version>.jar -role node -hub https://localhost:4444/grid/register

Here, it is important to define the –role to be a node. 

Configuring Nodes

When the user start the nodes, by default, it does allow for 11 browsers (5 Chrome, 5 Firefox and 1 Internet Explorer) for concurrent use. Thus, testers have the choice of conducting 5 concurrent tests by default. 

These conditions can be changed if the tester happens to configure the nodes. This can be achieved by passing parameters to each of the –browser switches which represent a node. When you use the browser parameter, the system ignores the default browser settings and only the specific parameters which are specified in the command line are used. 

Docker Selenium Grid

In this section, we shall look into what is a Selenium Grid Docker. 

Docker means a container which can be used to store different objects. Developers use this container for storing things like libraries, databases, dependencies and so on, in that container. These components or ingredients of the docker are then used for the creation, deployment and execution of applications. Docker is essentially helpful in packing up a software application, along with all its contents into one bundle and consequently shipping all of it out to one package.

Docker Selenium Grid

When a tester uses Selenium Grid, he is required to set up multiple virtual nodes, all of which are connected to a single centre which is the hub. Moreover, he is also required to download the Selenium server jar file and run them on each computer in which the Selenium Grid is supposed to be set up. This can be time consuming as well as an expensive activity. However, the Selenium Grid Docker helps in overcoming this issue as it helps in bundling up all the required components within a single frame.

Conclusion

By the end of this blog, I am pretty sure that you must have acquired a fair idea of what is Selenium Grid. Moreover, each version of Selenium Grid, be it in the form of Selenium Grid 2.0 or Selenium Grid 4, has been an attempt to rectify the shortcomings of the previous version. Selenium Grid especially does have an extremely important role to play in situations where it is technically not viable to execute all the test cases on a single machine.

sdet automation certification course