Hub in Selenium Grid
Hub is the central point (server) in Selenium Grid that:
- ✓Receives test execution requests from test scripts
- ✓Manages registrations from Nodes
- ✓Distributes test commands to the appropriate Node
- ✓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:
- ✓Listens on port 4444 (default) for incoming test requests
- ✓Accepts node registrations from machines that want to be test executors
- ✓Matches capabilities — when a test requests Chrome on Windows, Hub routes to a Node with those capabilities
- ✓Monitors node health — removes dead nodes automatically
- ✓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.
