TechBuzzPro

Selenium 4 Grid: New Features, Modes, and Setup

· 6 min read · Apps & Browsers

In this article
  1. Background: Why the Grid Was Rewritten
  2. New Features in Selenium 4 Grid
  3. Grid Modes: Standalone, Hub/Node, and Fully Distributed
  4. How to Set Up Selenium 4 Grid
  5. Common Problems and Misconceptions
  6. Comparison: Selenium 3 Grid vs Selenium 4 Grid
  7. Costs and Alternatives
  8. Frequently Asked Questions

Selenium 4 Grid introduces a fully rewritten architecture that simplifies setup, improves scalability, and adds native support for Docker and Kubernetes. The key changes are a unified distribution that runs all four Grid components (Router, Distributor, Node, and Session Map) with a single command, a new WebDriver-managed mode that removes the need for a separate Hub, and built-in support for observing and tracing requests. This article explains what’s new, how the modes work, and how to set it up in practice.

Background: Why the Grid Was Rewritten

The original Selenium Grid (introduced in Selenium 2) used a Hub-and-Node model. The Hub was a central server that received all test commands and forwarded them to registered Nodes, which ran the actual browser sessions. This worked for small to medium setups, but it had several limitations: the Hub was a single point of failure, the configuration was done through a separate JSON file, and scaling required manual management of Node registration and lifecycle.

Selenium 4 replaces this with a distributed architecture based on four independent components that communicate over HTTP and use the event bus for internal messaging. The new design decouples the request handling, session management, and node management, allowing each part to scale independently. This rewrite also aligns the Grid with the WebDriver W3C specification, so all communication between the client and the browser is now standardized.

New Features in Selenium 4 Grid

The most visible changes are:

  • Single JAR distribution: All Grid components are packaged into one executable JAR file, so you no longer need to download separate Hub and Node JARs.
  • Unified command: Running java -jar selenium-server-4.x.jar standalone starts a complete Grid in one process, which is perfect for local testing or CI pipelines.
  • Native support for Docker and Kubernetes: The Grid can dynamically create and destroy browser containers on demand, using the --detect-drivers option or the built-in Docker support in the Node component.
  • Built-in tracing: The Grid now generates OpenTelemetry traces, which can be exported to Jaeger or other tracing backends for performance analysis.
  • Observing and debugging: A new --log option provides structured logging, and the Grid exposes a REST API for querying status and session details.
  • Improved session handling: The Session Map component tracks all active sessions, and the Distributor assigns new sessions to the most suitable Node based on capabilities and current load.

Grid Modes: Standalone, Hub/Node, and Fully Distributed

Selenium 4 Grid can run in three distinct modes, each suited to different needs:

  • Standalone: All components run in a single process. This is the simplest mode and is ideal for local development or small test suites. Start it with java -jar selenium-server-4.x.jar standalone.
  • Hub/Node: The classic two-tier setup, but now the Hub is replaced by the Router, Distributor, and Session Map running together in one process. You start the hub with java -jar selenium-server-4.x.jar hub, and then start one or more nodes with java -jar selenium-server-4.x.jar node --detect-drivers true. Nodes register with the hub automatically.
  • Fully Distributed: Each component (Router, Distributor, Node, Session Map, and Event Bus) runs as a separate process. This is the most scalable mode and is intended for large, production-grade grids. You start the Event Bus first, then the Session Map, then the Distributor, then the Router, and finally the Nodes. Each component is started with its own command and configuration.

How to Set Up Selenium 4 Grid

Setting up a basic Grid is straightforward. Here’s a step-by-step guide for the standalone mode, which is the quickest way to get started:

  1. Download the latest Selenium Server JAR from the official Selenium releases page (e.g., selenium-server-4.25.0.jar).
  2. Make sure you have Java 11 or higher installed. Verify with java -version.
  3. Run the standalone server: java -jar selenium-server-4.25.0.jar standalone.
  4. By default, the Grid listens on port 4444. You can change the port with --port 4445.
  5. In your test code, set the WebDriver remote URL to http://localhost:4444 and use RemoteWebDriver with your desired browser capabilities.

For a hub/node setup, start the hub with java -jar selenium-server-4.25.0.jar hub, then start a node with java -jar selenium-server-4.25.0.jar node --detect-drivers true. The node will automatically register with the hub on the same machine. To run nodes on different machines, specify the hub address with --hub http://hub-ip:4444.

Common Problems and Misconceptions

One common misconception is that the Hub still exists in Selenium 4. In reality, the Hub process is replaced by the Router, Distributor, and Session Map. You can still use the hub command, but it starts those three components together, not the old Hub.

Another frequent issue is that the Grid fails to start because of a port conflict. The default port 4444 might already be in use. Check the logs for Port 4444 is already in use and use the --port flag to change it.

If you’re using Docker, a common mistake is not exposing the correct ports or not using the --publish 4444:4444 flag when running the container. Also, ensure that the browser containers have the correct VNC or noVNC ports exposed if you want to view the sessions.

Finally, many users expect the Grid to automatically manage browser versions. While the Grid can detect installed drivers, it does not manage browser versions. You need to ensure that the browser and the matching WebDriver executable are installed on each Node.

Comparison: Selenium 3 Grid vs Selenium 4 Grid

Here’s a quick comparison to highlight the key differences:

  • Architecture: Selenium 3 used a Hub-Node model; Selenium 4 uses a distributed event-driven architecture.
  • Configuration: Selenium 3 required a separate JSON config file for the Hub; Selenium 4 uses command-line flags and environment variables.
  • Scalability: Selenium 4 allows independent scaling of each component; Selenium 3 scaled only by adding more nodes.
  • Protocol: Selenium 4 fully implements the W3C WebDriver protocol; Selenium 3 had legacy JSON Wire Protocol support.
  • Docker integration: Selenium 4 has built-in Docker support for dynamic browser containers; Selenium 3 required external tools like Selenium Grid Extras.

Costs and Alternatives

Selenium Grid is open-source and free to use. The main costs are the infrastructure you run it on (servers, cloud instances, or Kubernetes clusters) and the time you spend maintaining it. If you prefer a managed service, alternatives include Sauce Labs, BrowserStack, and LambdaTest, which offer cloud-based grids with a subscription fee. These services handle the infrastructure and browser versions for you, but they are not free.

Another alternative is using a local test runner with parallelization, such as TestNG or JUnit’s built-in parallel support, but that only works on a single machine. For cross-browser testing on multiple machines, a Grid is still the standard solution.

Frequently Asked Questions

Do I need to download a separate Hub and Node in Selenium 4?

No. Selenium 4 ships as a single JAR file that contains all Grid components. You can run it in standalone mode, or start the hub and node using the same JAR with different command-line arguments.

How do I run Selenium Grid in Docker?

You can use the official Selenium Docker images. For example, run docker run -d -p 4444:4444 --name selenium-hub selenium/hub:4.25.0 for the hub, and then run a node with docker run -d -p 5555:5554 --link selenium-hub:hub selenium/node-chrome:4.25.0. Alternatively, use Docker Compose to define the entire grid.

What is the default port for Selenium 4 Grid?

The default port is 4444. You can change it with the --port flag when starting the Grid. For example, java -jar selenium-server-4.25.0.jar standalone --port 4445.

Can I use Selenium Grid with Kubernetes?

Yes. Selenium 4 has built-in support for Kubernetes through the Node’s --kubernetes flag, which allows the Grid to create browser pods on demand. You need to provide a Kubernetes configuration file that specifies the image and resource limits.

Does Selenium Grid support parallel test execution?

Yes. The Grid is designed to run multiple tests in parallel across different Nodes. You can control the number of concurrent sessions per Node using the --max-sessions flag when starting the Node.