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 MapDownload 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 DistributorRun 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 gets attached under Distributor process. If Selenium client code sends a create session request, then Distributor is responsible for assigning a node.
Step #3-Router ProcessAll the client requests will be received by Router. If the request is for creating a new session, then it will be redirected to Distributor process. All other requests will be sent to the node associated to the request after querying the node URI from Sessions Map using 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 nodeWhile creating a node, you no 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 is updated in Session Map. For thorough understanding, Please refer the below diagram.
java -jar selenium-server-4.0.0-alpha-2.jar node --detect-drivers
Step #5-Start a remote sessionInvoke 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("https://localhost:4444"),capability);
Once the session is created under the node, the session ID gets updated in 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 nodeApart from the session creation call, all other requests will be forwarded to Node from Router directly. Each client request has Session ID. Using the session ID, 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 weren’t aware of the process which happens at the back drop. Though the setup is complex. Modernization will help us to trouble-shoot failures and we can setup our own distributed execution elegantly.