---Advertisement---

Selenium Grid Tutorial: How to Set Up Hub and Node (Step-by-Step Guide) Great 2025

By Manisha

Updated On:

---Advertisement---
Selenium Grid Tutorial

πŸ‘‰Tutorial-1: Maven and Jenkins Integration
πŸ‘‰Tutorial-2: Selenium Framework

πŸ‘‰Tutorial-3: Database Testing with Selenium
πŸ‘‰Tutorial-4: How to Handle iFrames in Selenium WebDriver Using switchTo()
πŸ‘‰Tutorial-5: Cross Browser Testing using Selenium
πŸ‘‰Tutorial-6: Β How to Take Screenshot in Selenium
πŸ‘‰Tutorial-7: Log4j in Selenium
πŸ‘‰Tutorial-8: Headless Browser Testing in Selenium
πŸ‘‰Tutorial-9: Robot Class in Selenium WebDriver
πŸ‘‰Tutorial-10: AutoIT in Selenium WebDriver
πŸ‘‰Tutorial-11: Handling SSL Certificate Errors in Selenium
πŸ‘‰Tutorial-12: How to Handle AJAX Calls in Selenium
πŸ‘‰Tutorial-13: JavaScriptExecutor in Selenium WebDriver
πŸ‘‰Tutorial-14: Selenium Python Tutorial
πŸ‘‰Tutorial-15: How to Set Up IntelliJ IDEA with Selenium
πŸ‘‰Tutorial-16: Flash Testing Using Selenium WebDriver
πŸ‘‰Tutorial-17: Apache Ant with Selenium WebDriver
πŸ‘‰Tutorial-18: How to Generate XSLT Reports in Selenium
πŸ‘‰Tutorial-19: GitHub Integration with Selenium WebDriver and Jenkins
πŸ‘‰Tutorial-20: Handling Cookies in Selenium WebDriver
πŸ‘‰Tutorial-21: Using SoapUI with Selenium WebDriver
πŸ‘‰Tutorial-22: Cucumber with Selenium WebDriver
πŸ‘‰Tutorial-23: Selenium Firefox Profile
πŸ‘‰Tutorial-24: Drag and Drop in Selenium WebDriver with Practical
πŸ‘‰Tutorial-25: Selenium C# Tutorial
πŸ‘‰Tutorial-26: Object Repository in Selenium WebDriver
πŸ‘‰Tutorial-27: How to Scroll a Web Page in Selenium
πŸ‘‰Tutorial-28: Sikuli Integration with Selenium WebDriver
πŸ‘‰Tutorial-29: Master XPath in Selenium
πŸ‘‰Tutorial-30: Selenium Waits
πŸ‘‰Tutorial-31: Right Click and Double Click in Selenium WebDriver
πŸ‘‰Tutorial-32: How to Handle Proxy Authentication in Selenium
πŸ‘‰Tutorial-33: Comprehensive Guide to Exception Handling in Selenium


πŸ‘‰Selenium Grid Tutorial: What is Selenium Grid?

Selenium Grid Tutorial: Selenium Grid is a part of the Selenium Suite that allows you to run multiple tests across different browsers, operating systems, and machines in parallel. This is done using a Hub-Node architecture, where:

  • The Hub is the central server that manages test execution.
  • The Nodes are remote machines that run the tests.

Selenium Grid significantly reduces execution time by running multiple test cases simultaneously.


πŸ‘‰Selenium Grid Architecture

βœ” The Hub is the central server where test scripts are loaded.
βœ” There can only be one Hub in a Grid setup.
βœ” The Hub distributes test execution to connected Nodes.

βœ” Nodes are remote Selenium instances where the tests are executed.
βœ” A Grid can have multiple Nodes running on different machines and browsers.
βœ” Nodes can be on different operating systems than the Hub.

1️⃣ A user runs a test on the Hub.
2️⃣ The Hub routes the test to a Node that matches the required browser and OS configuration.
3️⃣ The Node executes the test and sends results back to the Hub.


πŸ‘‰How to Set Up Selenium Grid (Step-by-Step Guide)

Selenium Grid Tutorial: To configure Selenium Grid, we will use two machines:

  • Machine A (Hub) – Central server that distributes tests.
  • Machine B (Node) – Executes test scripts.

Let’s assume:

  • Machine A (Hub) has IP: 192.168.1.3
  • Machine B (Node) has IP: 192.168.1.4

1️⃣ Download the Selenium Standalone Server from the official Selenium website.
2️⃣ Save the .jar file in C:\ on both Machine A and Machine B.

1️⃣ Open Command Prompt on Machine A.
2️⃣ Navigate to C:\ using:

bashcd C:\

3️⃣ Start the Selenium Hub using:

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

4️⃣ Selenium Grid Tutorial: The Hub is now running. You can verify by opening a browser and navigating to:

arduinohttp://localhost:4444

1️⃣ Selenium Grid Tutorial: Open Command Prompt on Machine B.
2️⃣ Navigate to C:\ using:

bashCopyEditcd C:\

3️⃣ Start the Node and connect it to the Hub using:

pgsqljava -jar selenium-server-standalone-<version>.jar -role node -hub http://192.168.1.3:4444/grid/register

4️⃣ Verify the Node is registered by opening the Selenium Grid Console:

arduinohttp://192.168.1.3:4444/grid/console

At this point, your Selenium Grid is successfully set up, and you can start executing test cases remotely.


πŸ‘‰When to Use Selenium Grid?

Selenium Grid Tutorial: Cross-Browser Testing: Run tests on different browsers (Chrome, Firefox, Edge, etc.).
Cross-Platform Testing: Test applications on various operating systems (Windows, macOS, Linux).
Parallel Test Execution: Reduce test execution time by running multiple tests simultaneously.


πŸ‘‰Selenium Grid 1 vs. Selenium Grid 2

FeatureSelenium Grid 1Selenium Grid 2
Separate Remote ControlUses a different RC serverBundled with Selenium Server
Apache Ant InstallationRequiredNot required
Supports WebDriver?NoYes
Max Browsers per Remote Control1Up to 5

πŸ‘‰Designing Test Scripts for Selenium Grid

Selenium Grid Tutorial: To execute tests on Selenium Grid, we use:

  • DesiredCapabilities – Defines the browser and OS for the test.
  • RemoteWebDriver – Specifies the remote machine (Node) to run the test.
javaimport org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.MalformedURLException;
import java.net.URL;

public class SeleniumGridTest {
public static void main(String[] args) throws MalformedURLException {
DesiredCapabilities cap = new DesiredCapabilities();
cap.setBrowserName("chrome");
cap.setPlatform(Platform.WINDOWS);

WebDriver driver = new RemoteWebDriver(new URL("http://192.168.1.3:4444/wd/hub"), cap);
driver.get("https://www.google.com");
System.out.println("Title of the page: " + driver.getTitle());
driver.quit();
}
}

Explanation:
βœ” setBrowserName("chrome") – Specifies the browser.
βœ” setPlatform(Platform.WINDOWS) – Specifies the operating system.
βœ” new RemoteWebDriver(new URL("http://192.168.1.3:4444/wd/hub"), cap) – Connects to the Selenium Hub.


πŸ‘‰Configuring Sele:nium Grid with JSON

Selenium Grid Tutorial: Selenium Grid can also be configured using a JSON file instead of the command line.

1️⃣ Create a new text file hubConfig.json and add:

json{
"port": 4444,
"role": "hub"
}

Run this command:

pgsqljava -jar selenium-server-standalone-<version>.jar -role hub -hubConfig hubConfig.json

Selenium Grid Tutorial: Create a new text file nodeConfig.json and add:

json{
"capabilities": [{
"browserName": "chrome",
"maxInstances": 5
}],
"hub": "http://192.168.1.3:4444",
"role": "node"
}

Run this command on Machine B:

pgsql java -jar selenium-server-standalone-<version>.jar -role node -nodeConfig nodeConfig.json

Now your Selenium Grid is configured using JSON.


πŸ‘‰Summary

βœ”Selenium Grid Tutorial: Selenium Grid allows parallel test execution across different browsers, OS, and machines.
βœ” Hub-Node architecture distributes test execution efficiently.
βœ” Setup involves running a Hub and multiple Nodes.
βœ” Tests are executed using DesiredCapabilities and RemoteWebDriver.
βœ” JSON configuration provides an alternative setup method.

By setting up Selenium Grid, you can save time, ensure cross-browser compatibility, and improve test efficiency.

How to Customize

Testing Selenium Download 

Leave a Comment

Index