• Selenium Video Tutorials

Selenium Grid - Endpoints



The latest version of Selenium Grid 4, is developed without leveraging the code base of the older versions of the Selenium Grid. This latest version of Selenium Grid 4 version has some advanced features like the Grid endpoints.

The latest version of Selenium Grid allows test execution to be triggered in three different Selenium Grid modes. They are known as the Standalone, Hub and Nodes, and the Distributed.

Get Grid Status

The Grid status is used to provide details on the present condition of the Selenium Grid. The details include the information about all the registered nodes. For each individual node, the grid status tells if a node is available, and the sessions running on it along with the slot.

curl Get http://localhost:4444/status'

While the Selenium Grid is running in the Standalone mode, the Grid url points to the Standalone server address. In the Hub-Node mode, the Grid url points to the Hub server address and in the Distributed mode, the Grid url points to the Router server address.

In the above example, http://localhost:4444/status is the url used by default for all the modes mentioned above.

If there is a single Node, the Node url refers to http://localhost:5555.

The Node Status is used to measure the condition of the Node. The Distributor messages the node status at an interval and sends the same information to the Grid Model. This includes details about the availability, sessions, and slots.

cURL --request GET 'http://localhost:5555/status'

Remove Nodes From Selenium Grid

The curl command is used to remove a Node from the Selenium Grid. The removal of nodes from the Grid does not result in termination of any current session which is running in a Node. The session continues to execute unless it is specifically terminated. The Distributor does not have knowledge of Node and thus any similar new session request will not be forwarded to that specific Node.

While the Selenium Grid is running in the Standalone mode, the Distributor url refers to the Standalone server address. In the Hub-Node mode, the Distributor url refers to the Hub server address.

cURL --request DELETE
'http://localhost:4444/se/grid/distributor/node/<node-id>' 
   --header 'X-REGISTRATION-SECRET: <secret> '

In the fully distributed mode, the url points to the Distributor server address.

cURL --request DELETE 
'http://localhost:5553/se/grid/distributor/node/<node-id>' 
   --header 'X-REGISTRATION-SECRET: <secret>'

If the configuration for the registration secret is not done, at that we have to use the below command −

cURL --request DELETE 
'http://<Distributor-URL>/se/grid/distributor/node/<node-id>' 
   --header 'X-REGISTRATION-SECRET;'

Drain Node in Selenium Grid

The Node drain command is used to perform a Node shut down in a proper way. Draining a node indicates putting an end to the Node post completion of all the active sessions. After that, no other new session requests are accepted.

While the Selenium Grid is running in the Standalone mode, the Distributor url refers to the Standalone server address. In the Hub-Node mode, the Distributor url refers to the Hub server address.

cURL --request POST
'http://localhost:4444/se/grid/distributor/node/<node-id>/drain' 
   --header 'X-REGISTRATION-SECRET: <secret> '

In the fully distributed mode, the url points to the Distributor server address.

cURL --request POST
'http://localhost:5553/se/grid/distributor/node/<node-id>/drain' 
   --header 'X-REGISTRATION-SECRET: <secret>'

If the configuration for the registration secret is not done, for that we have to use the below command −

cURL --request POST 
'http://<Distributor-URL>/se/grid/distributor/node/<node-id>/drain' 
--header 'X-REGISTRATION-SECRET;'

Why Drain Command Used in Selenium Grid

The Distributor sends the drain command to the proper node with the help of the node id. In order to drain the Node by a direct route the below commands are used −

cURL --request POST 'http://localhost:5555/se/grid/node/drain' 
   --header 'X-REGISTRATION-SECRET: <secret>'

If the configuration for the registration secret is not done, for that we have to use the below command −

cURL --request POST 'http://<node-URL>/se/grid/node/drain' 
   --header 'X-REGISTRATION-SECRET;'

The endpoints used for the above commands are correct and yield the same results. Drain completes the active sessions prior to terminating the Node.

Check Session Owner in Selenium Grid

To check which session is a part of which Node, the below curl command is used −

cURL --request GET 
'http://localhost:5555/se/grid/node/owner/<session-id>' 
   --header 'X-REGISTRATION-SECRET: <secret>'

If the configuration for the registration secret is not done, for that we have to use the below command −

cURL --request GET 
'http://<node-URL>/se/grid/node/owner/<session-id>' 
   --header 'X-REGISTRATION-SECRET;'

Both the above commands will return true value, provided a particular session points to a Node, else false will be returned.

Delete Session in Selenium Grid

A webdriver session ends when a session is deleted. At this point, the driver is quitted, and separated from mapping of the active sessions. If any further request is processed or reused with the removed session id, the driver object shall give an error. The curl command to delete a session is −

cURL --request DELETE 
'http://localhost:5555/se/grid/node/session/<session-id>' 
   --header 'X-REGISTRATION-SECRET: <secret>'

If the configuration for the registration secret is not done, for that we have to use the below command −

cURL --request DELETE
'http://<node-URL>/se/grid/node/session/<session-id>' 
   --header 'X-REGISTRATION-SECRET;'

Clear New Session Queue in Selenium Grid

The New Session Queue stores the new session requests. To wipe out the queue, the below curl command is used. Once a queue is cleared, all the other requests in the queue are not accepted any more and the server gives an error response to its client.

While the Selenium Grid is running in the Standalone mode, the Queue url points to the Standalone server address. In the Hub-Node mode, the Queue url points to the Hub server address.

cURL --request DELETE 
'http://localhost:4444/se/grid/newsessionqueue/queue' 
   --header 'X-REGISTRATION-SECRET: <secret>'

In the properly Distributed mode, the Queue url points to the New Session Queue Server address.

cURL --request DELETE
\'http://localhost:5559/se/grid/newsessionqueue/queue' 
   --header 'X-REGISTRATION-SECRET: <secret>'

If the configuration for the registration secret is not done, for that we have to use the below command −

cURL --request DELETE
'http://<URL>/se/grid/newsessionqueue/queue' 
   --header 'X-REGISTRATION-SECRET;'

Get New Session Requests in Selenium Grid

The New Session Requests store the new session request. To obtain the present request in the queue, the below curl command is used. This command will yield the total count of the request in the queue, and their payloads.

While the Selenium Grid is running in the Standalone mode, the Queue url points to the Standalone server address. In the Hub-Node mode, the Queue url points to the Hub server address.

cURL --request GET
 'http://localhost:4444/se/grid/newsessionqueue/queue'

In the properly Distributed mode, the Queue url points to the New Session Queue Server address.

cURL --request GET 
'http://localhost:5559/se/grid/newsessionqueue/queue'

This concludes our comprehensive take on the tutorial on Selenium Grid - Endpoints. We’ve started with describing how to get the Grid Status, how to remove a node, what is a Drain Node, what is a Drain command, how to check and delete a session owner, how to clear the New Session Queue, and how to get new Session Requests in Selenium Grid.

This equips you with in-depth knowledge of the Selenium Grid Endpoints. It is wise to keep practicing what you’ve learned and exploring others relevant to Selenium to deepen your understanding and expand your horizons.

Advertisements