Listen to this blog
As we all are aware of the fact that, Selenium 4 has not been released yet. However, three alpha versions have been released. Selenium Grid has only two components Hub and Node. On the other hand in Selenium Grid 4, we have four components namely – Router, Sessions Map, Distributor, and Node. Selenium 4 has introduced new architecture for Grid. Let’s understand how Selenium Grid 4 works with the three new processes.
Step #1-Start Sessions Map
Download selenium-server-4.0.0-alpha-2.jar & Chrome Driver in a folder and run the below command to start Sessions Map process.
java -jar selenium-server-4.0.0-alpha-2.jar sessions
What is Sessions Map? Session Map is one of the Selenium Grid Processes. Whenever a node/session is created, Node URI/Session ID gets stored in Sessions Map. Why it is getting stored here is another question. You will understand this at the last step.
Step #2-Start Distributor
Run the below command to start the distributor process.
java -jar selenium-server-4.0.0-alpha-2.jar distributor --sessions http://localhost:5556
All Selenium Grid nodes get attached under the Distributor process. If Selenium client code sends a create session request, then Distributor is responsible for assigning a node.
Step #3-Router Process
All the client requests will be received by Router. If the request is for creating a new session, then it will be redirected to the Distributor process. All other requests will be sent to the node associated with the request after querying the node URI from Sessions Map using the Session ID. Use the below command to start the router process.
java -jar selenium-server.jar router --sessions http://localhost:5556 --distributor http://localhost:5553
Step #4-Create a node
While creating a node, you do need to pass all the driver details. Drivers will get auto-detected if the exe/binary files are available in the folder where you have saved the Selenium Server jar file. Once the node is created under the distributor, the node details along with Node URI are updated in Session Map. For a thorough understanding, Please refer to the below diagram.
java -jar selenium-server-4.0.0-alpha-2.jar node --detect-drivers
Step #5-Start a remote session
Invoke the remote webdriver which will send the creation request to router. Please note – Use http://localhost:4444. Not http://localhost:4444/wd/hub.
DesiredCapabilities capability = new DesiredCapabilities(); capability.setBrowserName("chrome"); RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444"),capability);
Once the session is created under the node, the session ID gets updated in the Session map for the node. So that Router can easily identify the node to send the other client requests directly.
Step #6-Router sends command to node
Apart from the session creation call, all other requests will be forwarded to Node from Router directly. Each client request has a Session ID. Using the session ID, the Router queries the Node URI
and finds the node which holds the session.
In the older version of Selenium Grid, these processes occur inside the Hub process. Hence we are not aware of the process which happens at the backdrop. Though the setup is complex. Modernization will help us to troubleshoot failures and we can set up our own distributed execution elegantly.