How to Set Up Selenium Grid for Parallel Testing
To set up
Selenium Grid, start a hub server that manages test requests, then connect one or more node servers that run tests on different browsers or machines. Use the selenium-server.jar with commands to start the hub and nodes, specifying browser types and machine details.Syntax
Hub start command: Starts the central server that controls test distribution.
java -jar selenium-server.jar hub
Node start command: Connects a machine to the hub to run tests on specified browsers.
java -jar selenium-server.jar node --hub http://<hub-ip>:<hub-port>/grid/register --detect-drivers
Explanation:
java -jar selenium-server.jar: Runs the Selenium server jar file.hub: Starts the hub server.node: Starts a node server.--hub: URL of the hub to register the node.--detect-drivers: Automatically detects installed browsers and drivers on the node machine.
bash
java -jar selenium-server.jar hub
java -jar selenium-server.jar node --hub http://localhost:4444/grid/register --detect-driversExample
This example shows how to start a Selenium Grid hub on your local machine and register a node that runs Chrome and Firefox browsers for parallel testing.
bash
1. Start the hub server: java -jar selenium-server.jar hub 2. Start the node server (on the same or different machine): java -jar selenium-server.jar node --hub http://localhost:4444/grid/register --detect-drivers
Output
21:00:00.000 INFO - Selenium Grid hub is up and running on port 4444
21:00:05.000 INFO - Node registered to the hub with browsers: chrome, firefox
Common Pitfalls
- Hub and node version mismatch: Ensure the Selenium server jar version is the same on hub and nodes.
- Incorrect hub URL: Nodes must register with the correct hub URL including port and path.
- Missing browser drivers: Nodes need proper browser drivers (e.g., chromedriver) installed and in PATH.
- Firewall or network issues: Nodes must be able to reach the hub over the network.
bash
Wrong node registration example: java -jar selenium-server.jar node --hub http://wrong-ip:4444/grid/register --detect-drivers Correct node registration example: java -jar selenium-server.jar node --hub http://localhost:4444/grid/register --detect-drivers
Quick Reference
Selenium Grid Setup Steps:
- Download the latest
selenium-server.jarfrom Selenium official site. - Start the hub with
java -jar selenium-server.jar hub. - Start nodes with
java -jar selenium-server.jar node --hub http://<hub-ip>:4444/grid/register --detect-drivers. - Verify nodes appear in the hub console at
http://<hub-ip>:4444/grid/console. - Run tests using RemoteWebDriver pointing to the hub URL.
Key Takeaways
Start the Selenium Grid hub first to manage test sessions.
Register nodes with the correct hub URL and ensure browser drivers are installed.
Use the same Selenium server version on hub and nodes to avoid compatibility issues.
Check the hub console to confirm nodes are connected and ready.
Network connectivity between hub and nodes is essential for proper operation.