Selenium 简明教程
Selenium Grid - Endpoints
最新的 Selenium Grid 4 版本是在不利用旧版 Selenium Grid 的代码库的情况下开发的。此最新版本的 Selenium Grid 4 中具有网格端点等一些高级功能。
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.
最新版本的 Selenium Grid 允许在三种不同的 Selenium Grid 模式下触发测试执行。它们被称为 Standalone、Hub 和 Nodes 以及 Distributed。
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
网格状态用于提供 Selenium Grid 当前条件的详细信息。此详细信息包括所有已注册节点的信息。对于每个单独的节点,网格状态会告知节点是否可用,以及在节点上运行的会话和插槽。
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'
在 Selenium Grid 以独立模式运行期间,网格 URL 会指向独立服务器地址。在 Hub-Node 模式下,网格 URL 会指向 Hub 服务器地址,而在分布模式下,网格 URL 会指向路由器服务器地址。
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.
在上方的示例中, http://localhost:4444/status 是所有上述模式都默认使用的 URL。
In the above example, http://localhost:4444/status is the url used by default for all the modes mentioned above.
如果存在单个节点,节点 URL 则引用 http://localhost:5555 。
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
curl 命令用于从 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.
在 Selenium Grid 以独立模式运行期间,分发器 URL 会引用独立服务器地址。在 Hub-Node 模式下,分发器 URL 会引用 Hub 服务器地址。
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> '
在完全分布模式下,此 URL 会指向分发器服务器地址。
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.
在 Selenium Grid 以独立模式运行期间,分发器 URL 会引用独立服务器地址。在 Hub-Node 模式下,分发器 URL 会引用 Hub 服务器地址。
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> '
在完全分布模式下,此 URL 会指向分发器服务器地址。
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
分发器利用节点 ID 将排空命令发送至适当节点。为了通过直接路由排空节点,使用以下命令:
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
若要检查会话属于哪个节点的一部分,可以使用以下 curl 命令:
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;'
上述两个命令都会返回 true 值(前提是特定会话指向某个节点),否则将返回 false。
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
当会话被删除时,webdriver 会话将结束。此时,将退出驱动程序,并将其从活动会话的映射中分离出去。如果使用已删除的会话 id 处理或重用任何进一步的请求,驱动程序对象将给出错误。用于删除会话的 curl 命令是 −
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
新会话队列存储新的会话请求。要清除队列,将使用以下 curl 命令。一旦清除队列,队列中所有其他请求将不再被接受,服务器将向其客户端发出错误响应。
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.
当 Selenium Grid 在独立模式下运行时,队列 URL 指向独立服务器地址。在 Hub-Node 模式下,队列 URL 指向 Hub 服务器地址。
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>'
在适当的分布式模式下,队列 URL 指向 New Session Queue Server 地址。
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
新的会话请求存储新的会话请求。要获取队列中的当前请求,将使用以下 curl 命令。此命令将给出队列中请求的总数及其有效负载。
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.
当 Selenium Grid 在独立模式下运行时,队列 URL 指向独立服务器地址。在 Hub-Node 模式下,队列 URL 指向 Hub 服务器地址。
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'
在适当的分布式模式下,队列 URL 指向 New Session Queue Server 地址。
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'
由此结束我们关于 Selenium Grid - 端点的教程的综合内容。我们首先介绍了如何获取网格状态、如何删除节点、什么是 Drain 节点、什么是 Drain 命令,如何检查和删除会话所有者,如何清除新的会话队列,以及如何在 Selenium Grid 中获取新的会话请求。
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.
这使你具备了有关 Selenium Grid 端点的深入知识。明智的做法是不断实践你所学的知识,并探索 Selenium 中与其他相关的内容,以加深你的理解并拓展你的视野。
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.