简体   繁体   English

Selenium Grid:如何以编程方式从HUB检索节点信息?

[英]Selenium Grid: How to retrieve node information from HUB programatically?

I am trying to run my selenium code using selenium grid. 我正在尝试使用硒网格运行我的硒代码。 Can someone please tell me how to retrieve system information (Like PC name , OS )of the node using java code 有人可以告诉我如何使用Java代码检索节点的系统信息(例如PC名称,OS)

There are multiple ways of doing it. 有多种实现方法。 The simplest of them would be to parse the user agent of the browser. 其中最简单的方法是解析浏览器的用户代理。 That gives you some basic information. 这为您提供了一些基本信息。

After you have launched the browser on the node via instantiation of RemoteWebDriver, you could simply do String userAgent = (String) driver.executeScript("return navigator.userAgent;"); 通过实例化RemoteWebDriver在节点上启动浏览器后,只需执行以下操作: String userAgent = (String) driver.executeScript("return navigator.userAgent;"); and then use a library such as UADetector for parsing the user agent string. 然后使用UADetector之类的库来解析用户代理字符串。 That should give you some information about the machine such as OS version/flavor, browser version etc., 这应该为您提供有关机器的一些信息,例如操作系统版本/风味,浏览器版本等,

If apart from this you also want the IP address of the node to which your test was routed to, you can refer to this blog post of mine. 如果除此之外,您还想要将测试路由到的节点的IP地址,则可以参考我的这篇博客文章。

If you would like to get more customized information from your node, here's what you would need to do: 如果您想从您的节点中获取更多的自定义信息,则需要执行以下操作:

  1. Build a node servlet and inject it into the node (You can refer here to learn how to do it ) 构建一个节点servlet并将其注入到节点中(您可以在这里参考以学习如何做)
  2. In the servlet, you can choose to build a JSON response which would capture all the information that you want to be sent back to the client (which in your case is the test code) 在Servlet中,您可以选择构建一个JSON响应,该响应将捕获要发送回客户端的所有信息(在您的情况下为测试代码)
  3. Use the logic that I have detailed in this blog to retrieve the IP address and the port of the node and then use that to hit your node servlet [ For eg, lets say 1.2.3.4, 5555 was the IP and port retrieved by (3) and your servlet was called as ExtraServlet, then your end point would be http://1.2.4.4:5555/extra/ExtraServlet 使用我在博客中详细介绍的逻辑来检索节点的IP地址和端口,然后使用该逻辑命中您的节点servlet [例如,假设1.2.3.4、5555是由(3 ),并且您的servlet被称为ExtraServlet,那么您的终点将是http://1.2.4.4:5555/extra/ExtraServlet

Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM