Selenium Grid – Architecture and Setup

Reading Time: 3 minutes

Ever thought of improving the delivery timelines? Running selenium tests on the local machine is not a stopping point for automation test scripts, rather it should have enhanced capabilities to run multiple test scripts on different runtime environments and operating systems. Here comes the role of Selenium Grid

What is Selenium Grid?

Selenium grid is the concept of selenium where the code we write is capable enough to run on different machines or virtual machines or cloud, unlike only local systems.
For example, sometimes there is a requirement to run a test on google chrome and at the same time tests requires to run on IE, firefox and safari.

Selenium grid follows a hub-node architecture. A hub is a master part and node is like the servant part. In a particular set up, there can be an only hub and multiple nodes.

Hub

  • Hub acts like Intermediary and manager
  • It Accepts requests to run tests
  • For instance, Takes instructions from client and executes them remotely on the nodes
  • Also, it Manages threads

Nodes

  • Where the browsers live
  • Registers itself to the hub and communicates its capabilities
  • Receives requests from the hub and executes them

Architecture

We write the code in local machine.

Consider a hub as a Server, it will redirect the commands to the respective node based on parameters.

The node is a actual machine where the code is executed.

Further, let us suppose a there is a requirement of a combination, windows with firefox version 52, to run a test on and these configurations exist on VM3.

Now, Hub will send the request to VM3 via the JSON wire protocol. All the commands like click, sendKeys will execute with the help of Webdriver on the required machine.

So, the hub decides which machine requires to execute the tests based on the requests we send through Desired Capabilities.

Since we can pass multiple browser configurations in Desired Capabilities, we are automatically achieving cross-browser testing in Parallel mode.

How to Set up the basic Selenium Grid?

In this section, we will use two machines. One for hub and other for node.

We need to download the Selenium jar files from here.

PreRequisite: Java should be installed and environment variables should be set.

To configure Hub, use the following command.

C:\Selenium Server> java -jar selenium-server-standalon-3.4.0.jar -role hub

This command would launch a Selenium Grid hub on port 4444 by default. You can also check the same by directing to http://localhost:4444/grid/console.

Hit enter and you will see the following screen

By this way hub configures itself, let us set up a node.
To set up a node, first, we need to register a node and connect them with the Hub. Every node connects to the IP address of Hub.
Selenium Grid hosts on 4444 which is the default port number on which on and listens for requests.

Node machine requires a similar configurations as that of hub i.e, Selenium jar files
Use the following command
java -Dwebdriver.chrome.driver=E:chromedriver.exe -jar selenium-server-standalone-3.4.0.jar -role node -hub http://192.168.0.11:4444/grid/register

Path of the browser driver is now set and node successfully registers with the hub.

To read more about selenium concepts visit here.

References :

https://www.lambdatest.com/blog/setup-selenium-grid-for-parallel-execution/
https://www.youtube.com/watch?v=6nq1dOiTdC8
https://www.youtube.com/watch?v=P8yq37Qr4eo
https://www.selenium.dev


Knoldus-blog-footer-image

+ posts

Nearly 3 years of experience in automation testing, I call myself an automation enthusiast. I can create, execute automated test scripts using framework guidelines and best practices to ensure wider and efficient end-to-end automation coverage.
Simultaneous experience in Defect tracking and bug reporting through JIRA

Written by 

Nearly 3 years of experience in automation testing, I call myself an automation enthusiast. I can create, execute automated test scripts using framework guidelines and best practices to ensure wider and efficient end-to-end automation coverage. Simultaneous experience in Defect tracking and bug reporting through JIRA