2

When working with Selenium Server, it would be very useful to log the name of the machine that actually does the execution of the selenium script. Is it possible to get that information?

I am working with C# bindings, but answer in any language would do fine.

Aleksandrs Ulme
  • 1,262
  • 1
  • 12
  • 21

2 Answers2

2

Here's how to do this in Grid.

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.
Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66
2

We should know where the Selenium Server is running.

This is Java Code :

we have straight method for this in HttpCommandExecutor class, getAddressOfRemoteServer()

code for Firefox :

RemoteWebDriver rcw = new RemoteWebDriver(new URL("http://serveraddress:portnumber/wd/hub"), DesiredCapabilities.firefox())

so if you have an instance of RemoteWebDriver

rcw.getCommandExecutor().getAddressOfRemoteServer()

code for IE :

Same as Above OR for Local

((HttpCommandExecutor)(new InternetExplorerDriver().getCommandExecutor())).getAddressOfRemoteServer();

Henry Woody
  • 14,024
  • 7
  • 39
  • 56
sudarsan
  • 283
  • 1
  • 4
  • 1
    Doesn't this return the address of the hub rather than the node? i.e. in your example it will return "http://serveraddress:portnumber/wd/hub" – WW. Dec 04 '16 at 23:41