</>

Technology

Selenium

Difficulty

Beginner

Interview Question

What is a Hub in Selenium Grid?

The Hub is the central server in Selenium Grid that receives test requests, manages node registrations, and routes test commands to the appropriate browser nodes.

Answer

Hub in Selenium Grid

Hub is the central point (server) in Selenium Grid that:

  1. Receives test execution requests from test scripts
  2. Manages registrations from Nodes
  3. Distributes test commands to the appropriate Node
  4. Tracks the status of all connected Nodes

Role of the Hub:

CODE
Test Script → [HUB: port 4444] → routes to → [Node with matching capabilities]

Starting the Hub:

Bash
# Selenium 3 — standalone jar
java -jar selenium-server-standalone-3.141.59.jar -role hub

# Access console at: http://localhost:4444/grid/console

Selenium 4 Hub:

Bash
java -jar selenium-server-4.x.x.jar hub

# Access at: http://localhost:4444

What the Hub does:

  1. Listens on port 4444 (default) for incoming test requests
  2. Accepts node registrations from machines that want to be test executors
  3. Matches capabilities — when a test requests Chrome on Windows, Hub routes to a Node with those capabilities
  4. Monitors node health — removes dead nodes automatically
  5. Returns results to the test script

Hub configuration example:

JSON
{
  "port": 4444,
  "host": "localhost",
  "maxSession": 50,
  "browserTimeout": 60
}

How test connects to Hub:

Java
// Test points to Hub URL, not a local driver
WebDriver driver = new RemoteWebDriver(
    new URL("http://hub-server:4444/wd/hub"),
    new ChromeOptions()  // Hub routes to a Chrome node
);

Hub in context:

CODE
[TestNG Suite]
     ↓
[RemoteWebDriver → http://hub:4444/wd/hub]
     ↓
[HUB] ←—— registered ——— [Node 1: Chrome/Windows]
 |                         [Node 2: Firefox/Mac]
 |—routes based on caps——→ [Node 3: Safari/Mac]

Key definition: A Hub is a server or a central point that controls the test executions on different machines. It does not execute tests itself — it delegates to Nodes.

Follow AutomateQA

Related Topics