All Posts

What is Selenium Router?

What is Selenium Router?

In this tutorial, we will learn about Selenium Router. Router grid component is new feature in Selenium 4.0 Grid Architecture.

Selenium Router is a component of Selenium Grid 4 that acts as the central entry point for WebDriver requests. It receives automation requests from Selenium clients and routes them to the appropriate browser session running on an available Node.

In simple terms, the Selenium Router works like a traffic controller: it receives requests, identifies the correct browser session or available machine, and forwards the requests to the right destination.

Selenium Router

Router is the entry point of the client requests. Router can receive two types of requests.

  • New session request
  • ‘Sticky’ request to an existing session

When a Router receives a new request, the request is added to the Session Queue.

https://www.testingdocs.com/what-is-selenium-session-queue/

Sticky request are requests for an existing session. If the request is sticky the Router will send the session-id information to the SessionMap, and in turn  returns the worker node info where the existing session is currently running.

https://www.testingdocs.com/what-is-selenium-sessionmap/

Why do we need Selenium Router?

Imagine you are running 100 Selenium automation test cases across multiple browsers and machines.

Instead of connecting your test scripts directly to individual machines, you can send all WebDriver requests to the Selenium Grid Router.

The Router handles request routing, allowing tests to execute across multiple machines and browsers.

How to Start?

Launch command prompt or Terminal

Run the following command. Replace the jar name with the actual name within the angle brackets.

\> java -jar <selenium-4-server.jar> router –sessions <url> –distributor <distURL> –sessionqueue <queueURL>

Selenium Router

To know more information on the command line switches issue the following command :

\> java -jar <selenium-server-4.jar>  router –help

 

Router vs Distributor vs Node

Feature Router Distributor Node
Receives client requests Yes No No
Finds available browser machines No Yes No
Routes existing sessions Yes No No
Starts browser sessions No Assigns the Node Yes
Executes Selenium commands No No Yes

Important Interview Point

The Selenium Router does not execute automation test cases or select the browser machine itself. It routes requests. The Distributor assigns new sessions to suitable Nodes, and the Nodes execute the browser automation.