</>

Technology

Selenium

Difficulty

Intermediate

Interview Question

What is Selenium Grid?

Selenium Grid is a tool that enables distributed running of test scripts across multiple machines with different browsers and platforms in parallel.

Answer

Selenium Grid is a tool that helps in distributed running of test scripts across different machines having different browsers, browser versions, and platforms — all in parallel.

Architecture:

  • Hub — the central server that manages all distributed machines (nodes). It receives test requests and assigns them to available nodes.
  • Node — the machines attached to the hub where tests actually execute.
CODE
         [Hub - Central Server]
         /          |          \
   [Node 1]    [Node 2]    [Node 3]
   Chrome      Firefox      Safari
   Windows     Linux        macOS

Benefits:

  1. Parallel execution — multiple tests run simultaneously, drastically reducing total test time
  2. Multi-browser testing — run on Chrome, Firefox, Edge, Safari at the same time
  3. Multi-platform testing — run on Windows, Linux, macOS simultaneously
  4. Scalable — add more nodes to handle more tests

Selenium 4 Grid — Quick start:

Bash
# Standalone mode (hub + node in one)
java -jar selenium-server-4.x.jar standalone

# Or hub mode
java -jar selenium-server-4.x.jar hub

# And on another machine start a node
java -jar selenium-server-4.x.jar node --hub http://hub-ip:4444

Connect test to Grid:

Java
ChromeOptions options = new ChromeOptions();
RemoteWebDriver driver = new RemoteWebDriver(
    new URL("http://hub-ip:4444"), options
);

Follow AutomateQA

Related Topics