3

I obtain a RemoteWebDriver from the hub as follows:

RemoteWebDriver driver = new RemoteWebDriver( 
                                      new URL("http://whatever:4444/wd/hub"),
                                      DesiredCapabilities.internetExplorer() );

Is there a way to programatically find out which node in the grid the remote driver is running on?

I want to log this in an effort to track down intermittent test failures.

WW.
  • 23,793
  • 13
  • 94
  • 121
  • Possible duplicate of [How to get executing server name or address with Selenium Server 2.20](http://stackoverflow.com/questions/9771932/how-to-get-executing-server-name-or-address-with-selenium-server-2-20) – Ralph Ritoch Dec 02 '16 at 05:08
  • The accepted answer to the duplicate question is wrong. – WW. Dec 05 '16 at 02:43

1 Answers1

5

Please refer to this blog post of mine to learn how to find out the node ip and port to which the test was routed to.

Blog post : https://rationaleemotions.wordpress.com/2016/01/15/where-did-my-test-run/

In a nutshell, here's what you need to do (The blog I shared has elaborate explanation and required code )

  • Get the session id from webdriver via Webdriver.getSessionId()
  • You then append the session id obtained from the previous step to the URL http://localhost:4444/grid/api/testsession?session= (replace localhost with the actual Grid IP/host and replace 4444 with the port on which grid is listening to) and trigger a POST call.
  • From the JSON response you parse the value of attribute proxyId as a URL and extract out the IP and port from it.

This is now available for ready consumption via the library talk2grid that I built.

Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66