NashTech Insights

Getting Started for Cross Browser testing with Selenium Grid 

Gargi Sanadhya
Gargi Sanadhya
Table of Contents
woman coding on computer

In the era, where there are multiple platforms available to access web applications, it has become the responsibility of the test automation engineers to ensure cross-browser compatibility. To have these devices physically present in one place and execute your test cases on each device is a tiresome job and an exhaustive approach.  
With the increased demand for automated testing on the application layer of web applications, it is also necessary to make these automated tests execute on various devices in time efficient manner.  
To cope with this, we have Selenium Grid. Selenium Grid helps you to allow your test cases to be executed on different platforms. 

What is Selenium Grid?

Most of us have listened about a very popular automation tool: Selenium. Sometimes, people confuse the Grid as a front-end automation testing tool. However, the scope of Selenium is very vast.  
As per the official documentation of Selenium, it is not just a tool, but it is composed of many tools. Grid is also a part of this composition. 

  • Grid is a component of the Selenium testing framework that allows you to distribute and execute your tests on various platforms.  
  • The control to trigger the test is at your local end and once triggered, these tests are executed remotely across various platforms 

Architecture and Function

Function of the Selenium Grid 

  • Client
    • Entities that initiate the test execution and interact with the Selenium Grid
    • Communicate with the hub to request test execution and receive information about available nodes and their capabilities. 
    • It can be various testing tools, scripts etc. That can interact with Selenium Grid. 
  • Hub
    • Hub manages test distribution and coordination. 
    • Receives the test requests from the clients and distributes them among the available nodes
    • Also, it tracks the availability and status of the nodes
  • Nodes
    • It can be any physical or virtual device which executes the tests. 
    • It shares its capability with the hub such as operating system, browser and its version. 
    • It launches and manages the browser instances for running the tests  

Components of Selenium Grid

  • Distributor 
    • The distributor registers the node and keeps track of all the nodes and their capabilities. 
    • Every new session request is forwarded to New Session Queue where the distributor polls for every pending session and assign the suitable node to the session 
  • Router
    • It is the entry point of the grid, receiving all requests and forwarding them to the suitable component. 
  • Session
    • It keeps the information about the session and the node assigned to the respective session 

Executing your first test in Selenium Grid

Pre-requisites for the Selenium Grid

  • Java 11 or higher 
  • Browsers installed 
  • Browser Driver 
    • For Selenium Web Driver 4.6 and above, the drivers are automatically configured using Selenium Web Driver Manager. In this blog, we are going to use it instead of using web driver files. 
    • Or Drivers installed, and on the same path as Grid Jar File 
  • Selenium Grid Jar, the latest version can be downloaded from Selenium Grid latest release 

Quick Setup and Start a Grid Server in Distributed (Hub and Nodes) Role 

Hub and node setup combines different machines into a single grid. It provides a single-entry point for the test execution on different environments. This is the most used way to initialise the Grid server.

  • Execute the following command at the location where your jar file is saved
    • java -jar selenium-server-4.9.1.jar hub
    • This will initiate a hub and you can check if the Grid server has been initialised while navigating to the following URL in your web browser 
    • You will see the below page on the above location. 
  • Execute the command on the same machine where the hub is executing in another terminal window
    • java -jar selenium-server-4.9.1.jar node --selenium-manager true 
    • We have added the –selenium-manager true option to automatically configure the web browser drivers. 
    • Now, you will see a node created on your Selenium Grid. 

Start a Grid Server in a Standalone role

In standalone, you will get a fully functional grid with a single command, under a single process. You can run it on a single machine. This is mostly used to design and debug tests locally, have a quick check over your created test etc. 
The below command will help to initiate Grid Server in a standalone role: 

  • java -jar selenium-server-<version>.jar standalone --selenium-manager true 

Adding meta data in your tests

On your test suite, add the following code snippet in your base class. 

ChromeOptions chromeOptions = new ChromeOptions(); 
// Add the desired OS here  
 chromeOptions.setCapability("platformName", "linux"); 
// Added a test name instead of the session id in the Grid UI 
 chromeOptions.setCapability("se:name", "Demo Test"); 
// Other type of metadata can be seen in the Grid UI by clicking on the 
// session info or via GraphQL 
 chromeOptions.setCapability("se:sampleMetadata", "Sample metadata value"); 
 driver = new RemoteWebDriver(new URL("http://localhost:4444"), chromeOptions); 

Now, execute your tests and hence you can see active sessions under the Session menu available on Grid Remote URL. 

Here, we can run 6 sessions in parallel using the Selenium grid. We have used it here for a single browser and machine to kick off the Selenium Grid. However, we can execute our tests on multiple platforms and browsers using Selenium Grid. 

Why Selenium Grid over other cloud testing platforms? 

  • Open Source:
    • It is an open-source technology. This means that you have large community support, rapid bug-fixes and enhancements.
    • On the other hand, cloud testing platforms are mostly paid software and hence, the support is limited. 
  • Flexibility: 
    • You can customize the hardware, configuration and other things as compared to other cloud testing platforms.
    • As a tester, you have full control over the test environment that you desired. 
  • Data Privacy and Security:
    • When an organisation is dealing with sensitive data, Selenium Grid is always top of the game. It allows you more secure and private execution.
    • There may be increased security concerns while testing on cloud testing platforms as your application code and other things are shared with third-party vendors. 
  • Network Isolation:
    • There are some web applications which require controlled network requirements, a replication of the production environment.
    • Grid allows you to set up VPN for your test nodes providing realistic test conditions. 
  • Reduced Latency:
    • In Grid, the tests execute on the local network or machines, and the latency is reduced, resulting in faster test execution and more precise performance measurements. 
  • Integration:
    • Integration with the existing framework and CI/CD pipelines are more adaptable than third-party cloud testing platforms.
    • These platforms may sometimes require changing your current flow for execution. 


Selenium Grid is a beneficial tool mostly for web applications where cross browsers compatibility has utter importance, especially with D2C domains such as e-commerce. These domains have large number of audiences and consumers, and they are going to run the application on various platforms, browsers etc. This is where Grid emerged as a flexible, reliable tool to verify the cross-browser compatibility. 

Gargi Sanadhya

Gargi Sanadhya

Leave a Comment

Your email address will not be published. Required fields are marked *

Suggested Article

%d bloggers like this: