---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