首页 > 解决方案 > 除了 http://localhost:4444/grid/console 之外,有没有办法通过 Selenium Grid 获取注册节点的数量

问题描述

为了并行运行多个测试,我想知道有多少节点已经在某个时候运行。

我查看了很多关于这个主题的帖子,但所有帖子都包括使用http://localhost:4444/grid/console:我不想查看这个页面。我正在考虑每次创建节点时向集线器发送一条消息。因此集线器会增加其计数。但我找不到办法做到这一点。

有没有人有不同的解决方案?也许使用 seleniumgrid 参数或命令,我很惊讶这个数字没有存储在某个地方?

标签: seleniumselenium-grid

解决方案


selenium 网格有一个 API。你可以这样做:

http://hub_ip_address:4444/grid/api/hub

并解析它为“slotCounts”返回的 json

{
  "success":true, 
  "capabilityMatcher":"org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
  "newSessionWaitTimeout":-1,
  "throwOnCapabilityNotPresent":true,
  "registry":"org.openqa.grid.internal.DefaultGridRegistry",
  "cleanUpCycle":5000,
  "custom":{

  },
  "host":"XX.XXX.XX.XXX",
  "maxSession":10,
  "servlets":[
     "ConsoleServlet"
  ],
  "withoutServlets":[

  ],
  "browserTimeout":0,
  "debug":false,
  "port":4444,
  "role":"hub",
  "timeout":300000,
  "enablePassThrough":true,
  "newSessionRequestCount":0,
  "slotCounts":{
     "free":9,
     "total":12
  }
}

推荐阅读