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:
- ✓Parallel execution — multiple tests run simultaneously, drastically reducing total test time
- ✓Multi-browser testing — run on Chrome, Firefox, Edge, Safari at the same time
- ✓Multi-platform testing — run on Windows, Linux, macOS simultaneously
- ✓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
);
