Dani
Dani

Reputation: 183

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

Upvotes: 1

Views: 1796

Answers (1)

Krishnan Mahadevan
Krishnan Mahadevan

Reputation: 14746

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;"); and then use a library such as UADetector for parsing the user agent string. 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.

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 )
  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)
  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 e.g., 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

Hope that helps.

Upvotes: 2

Related Questions