Selenium Grid Tutorial: Complete Guide for Beginners


Selenium Grid allows tests to run across multiple browsers, devices, and operating systems at the same time. Instead of running the full suite on one machine, it distributes execution across several machines, which reduces test time and expands environment coverage.
The Grid uses a hub-and-node model. The hub acts as the controller, while nodes are the executors that run tests on specific browsers and versions. However, with version 4, Selenium Grid introduces a new architecture and enhanced features that make distributed and parallel testing more practical.
This guide explains the concepts, key components, and a step-by-step setup to help you use Selenium Grid effectively.
What is Selenium Grid and How Does it Work?
Selenium Grid is a part of the Selenium suite that focuses on distributed test execution. Instead of limiting tests to a single system, it allows them to run on multiple machines at the same time. Each machine can have a different operating system, browser, or browser version, which makes it possible to cover a wide range of environments.
The core idea is that there is a central hub which receives test requests, and there are multiple nodes connected to the hub. The hub decides which node should execute a given test based on the requested configuration. This division of work enables parallel testing and faster feedback.
Here’s how the process works:
- A test script specifies the desired environment such as browser type and version
- The request goes to the hub which acts as the manager
- The hub checks available nodes that match the requested setup
- The selected node launches the browser and runs the test
- Results are then sent back through the hub to the test framework
This allows teams to scale their testing strategy without being tied to one local system. By adding more nodes, the capacity to run parallel tests grows, and coverage across different environments becomes more reliable.
Why Teams Use Selenium Grid for Distributed Testing
As test suites expand, running everything on a single machine slows down execution and reduces coverage. Selenium Grid solves this by enabling parallel testing across environments and distributing the load efficiently.
The main reasons teams rely on Selenium Grid include the following:
- Parallel execution: Multiple tests run at the same time across different machines, which cuts down total execution time significantly
- Cross-browser coverage: Nodes can be set up with different browsers and versions, ensuring the application is validated against a complete test matrix
- Cross-platform validation: Tests can run on various operating systems without maintaining separate local setups for each one
- Resource utilization: Workloads are spread across nodes, which prevents overloading a single system and makes better use of available hardware
- Scalability: Teams can add or remove nodes as project needs grow, making it easy to scale testing capacity without major changes
- Reliable environments: Nodes are configured with specific browser and OS versions, which reduces inconsistencies that may occur with ad hoc local testing
Selenium Grid 4 Architecture Overview
Selenium Grid 4 introduced a new architecture that makes distributed testing more reliable and easier to manage. It replaced the older hub-and-node command line setup with a system of services that can run in different modes.
The main parts of the architecture are as follows:
- Router: Acts as the entry point for all test requests and directs them to the appropriate component within the Grid
- Distributor: Decides which node should execute a test by checking availability and matching requested capabilities
- Session Map: Maintains information about active test sessions so the Grid knows where each session is running
- Event Bus: Handles communication between services, ensuring updates and messages flow consistently
- Nodes: Run the actual browser instances and execute the tests, each configured with specific environments
- Hub role: Functions as a combination of router, distributor, and session map when Grid is run in a single-process mode
This modular structure gives teams flexibility. Grid can be run as one process for simplicity or as distributed services for large-scale projects.
Core Features That Make Selenium Grid Effective
Selenium Grid is not only about running tests in parallel. It has several built-in features that make large-scale test automation practical and dependable for teams of all sizes.
The most important features include:
- Parallel test execution: Multiple tests can run at the same time, which shortens overall execution cycles and speeds up feedback loops
- Cross-browser testing: Nodes can host different browsers and versions, allowing teams to confirm application behavior across a complete browser set
- Cross-platform support: The Grid can connect nodes on different operating systems, giving full visibility into how the application performs in varied environments
- Centralized management: A single hub manages requests, distributes sessions, and tracks results, reducing the complexity of coordinating test runs
- Scalable architecture: Teams can start small with one or two nodes and scale to dozens or hundreds without redesigning the setup
- Session tracking: The session map ensures active sessions are properly managed and routed, which reduces errors in distributed execution
- Flexible deployment: Grid 4 can run as a single process for small setups or as multiple services for enterprise-level distributed testing
Main Components of Selenium Grid 4
Selenium Grid 4 is built around modular services. Each service has a specific responsibility, and together they manage distributed test execution in a structured way.
The main components are:
- Router: Serves as the entry point for all incoming test requests and routes them to the correct service inside the Grid
- Distributor: Matches requests with available nodes by checking browser type, version, and platform before assigning execution
- Session Map: Stores the mapping of active test sessions and ensures the hub knows exactly where each test is running
- Event Bus: Acts as the messaging system that allows different services to communicate and stay updated about session states
- Nodes: Run the actual browser instances and execute tests, each configured with specific environments like Chrome, Firefox, or Edge on various OS versions
- Hub (Standalone Mode): Combines router, distributor, session map, and event bus into a single process for smaller setups or local testing needs
Together, these components create a flexible system that can scale from simple local execution to enterprise-level distributed testing.
Step-by-Step Setup of Selenium Grid
Setting up Selenium Grid 4 involves preparing the Grid package, starting the services, and configuring nodes to run your tests. Below is a breakdown of each step in the process.
1. Install the Grid Package
You first need the Selenium Server jar file, which contains everything required to run Grid 4. It is available on the official Selenium downloads page. Once downloaded, keep it in a known directory so you can launch services directly from there. Java 11 or higher must be installed and available in your system path.
2. Launch the Hub
In Grid 4, the hub is no longer a separate jar but a role that can be launched with the Selenium Server. You can start the hub in standalone or hub mode depending on your needs. For a distributed setup, run the hub service with the command:
java -jar selenium-server-.jar hub
This starts the hub service, which will wait for incoming node registrations.
3. Launch the Nodes
Nodes are the executors that run browser sessions. Each node must register with the hub. Start a node with the following command:
java -jar selenium-server-.jar node --detect-drivers true
The option —detect-drivers true automatically detects browser drivers installed on the system. Nodes then become available to take up test sessions from the hub.
4. Configure Node Settings
Nodes can be configured to run specific browsers, versions, or limit the number of parallel sessions. Configuration is done through JSON files or command-line arguments. For example, you can restrict a node to handle only Chrome or set a maximum of five parallel sessions. This ensures controlled use of system resources.
5. Execute Tests on the Grid
Once the hub and nodes are running, test scripts must be updated to point to the Grid hub URL instead of the local driver. The typical hub URL looks like this:
http://localhost:4444/wd/hub
Desired capabilities in the test script specify which browser and platform should be used, and Grid automatically assigns the request to a matching node.
Running Parallel Tests with Selenium Grid
One of the main advantages of Selenium Grid is the ability to run tests in parallel. Instead of executing test cases one after another, multiple tests can be distributed across different nodes at the same time. This not only saves execution time but also helps validate the application under varied conditions.
The key points to know when running parallel tests are:
- Test framework support: Frameworks like TestNG, JUnit, and NUnit provide built-in features for parallel execution, which can be combined with Grid for distributed runs
- Desired capabilities: Each test must define browser type, version, and platform so the hub can match it to a suitable node
- Thread management: Parallel execution requires careful handling of test threads to avoid resource conflicts and ensure independent execution
- Resource allocation: Nodes should be configured with limits on concurrent sessions to prevent system overload and ensure stable execution
- Result handling: Test frameworks collect and merge results from parallel runs, so reports reflect the outcome of all distributed sessions
Conclusion
Selenium Grid lets teams run tests in parallel across multiple browsers and operating systems. Set up the hub and nodes, configure node capabilities, and point your tests to the hub URL. Start with a small grid to validate configuration and then scale by adding nodes and tuning session limits to match hardware and test patterns.
Platforms like BrowserStack provide a cloud-based Selenium Grid with instant access to thousands of real devices and browsers. Instead of setting up and maintaining infrastructure, teams can connect their existing Selenium tests to BrowserStack and run them at scale on real environments with better speed and accuracy.

Contents
Subscribe for latest updates
Share this article
Related posts











