NashTech Insights


Hitesh Mahi
Hitesh Mahi
Table of Contents

Hello readers, today we will learn about Selenium Grid and its significance and understand the basics

What is Selenium Grid?

It is the concept of selenium where our written code runs on different machines, virtual machines, and local systems. Sometimes there is a requirement to run tests on Chrome browser while our tests require running on Firefox and Safari.

It follows a hub-node architecture. The hub is a master part and the node is a servant part. In a particular setup, there can be only a hub and multiple nodes now let us discuss nodes and hubs in a more detailed manner.

What are Nodes

  1. They are the selenium instances that will execute the test cases that you loaded on the hub.
  2. Launched on multiple machines with different platforms and browsers.
  3. There can be more than one node in a grid
  4. Each node represents a particular Instance and will have their own Execution

What are Hubs

  1. A Hub is a central point or a local machine that receives all the test requests and distributes them to the right nodes.
  2. It is responsible to trigger the test case.
  3. There can be only a single hub.
  4. Hub is Responsible for receiving the requests and taking necessary actions against each request sent by the node.

Hub and Node Architecture

Why Selenium Grid?

It has the following advantages as mentioned below:-

  • Platform Independent: It is platform independent as we can run the test cases on different platforms like Windows, Mac, Android, etc
  • Parallel execution: If you set up the Selenium Grid, you can run multiple cases at the same time. This saves time in running the test suites.
  • Language Support: Selenium grid supports multiple languages like Java, Python, JavaScript, C#, Ruby, and Perl programming languages for test automation.
  • Multiple Browser Support: It supports all popular web browsers like Chrome, Firefox, Safari, Internet Explorer, Microsoft Edge, etc.
  • Open Source and Free: Selenium is an open-source and free platform so everyone has access to use and automate the test cases so as selenium grid.

Selenium grid components in detail: 

The components are listed as follows:-

  • Router
  • Distributor
  • Session Map
  • New Session Queue
  • Node
  • Event Bus
  • Hub

To understand more about the components please refer to this link.

Set Up Selenium Grid

Please refer to this link for detailed installation steps.

Sample Code

Below is the code snippet that demonstrates how to run a simple grid

import org.openqa.selenium.*; 
import org.openqa.selenium.remote.DesiredCapabilities; 
import org.openqa.selenium.remote.RemoteWebDriver; 
import org.testng.Assert;
import org.testng.annotations.*; 

public class Simple {
 WebDriver driver;
 String baseUrl, nodeURL; 
 public void setUp throws MalformedURLException {
 baseUrl = "";
 nodeURL = ""; 
 DesiredCapabilities capability = DesiredCapabilities.firefox();
 capability. setBrowserName("firefox");
 capability. setPlatform(Platform.XP);
 driver = new RemoteWebDriver(new URL(nodeURL), capability); 
public void afterTest() {


public void simpleTest() { 
 Assert.assertEquals("Welcome: Mercury Tours", driver.getTitle()); } 

First, we import the necessary packages for RemoteWebDriver and then pass the DesiredCapabilities object that we created above as a parameter for the RemoteWebDriver object

DesiredCapabilites is used to set the type of browser and operating System that we want to automate.
RemoteWebDriver is used to set which node our test will run against it.

Then we set up the node URL and base URL invoking the desired capabilities object and calling its methods setPlalform() and setBrowserName() then add a test which is asserting the title and after the test has been executed it simply quits the application.


So today we have learned about this topic and its significance and basics for setup. I hope this post will prove to be useful, See you again!



Proudly powered by WordPress

Hitesh Mahi

Hitesh Mahi

Hitesh is working as a Software Consultant at Nashtech he is keen to know about new technologies and top skills like backend testing using postman hobbies are content making and singing

Suggested Article

%d bloggers like this: