Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium Grid: How to get node name (computer name or IP address) where current test is executed

I execute my tests under Grid Hub and 3 nodes run on 3 remote computers. In my log I can see the messages in random order posted from all these nodes. In order to analyze the logs I have to sort it by computer name. I tried it in following way (Java):

System.getenv().get("COMPUTERNAME")

But every time it returns the name of computer where Hub is running.

like image 446
Dima Star Avatar asked Jul 27 '12 15:07

Dima Star


People also ask

Can we use Selenium grid for performance testing?

Using a selenium grid for performance testing gives you the advantage of being able to easily and quickly implement performance tests into your continuous testing environment re-purposing familiar selenium tests as performance tests.

What is the main node that contains everything in the configuration file for your tests in Selenium?

The hub is the central point wherein you load your tests. Nodes are the Selenium instances that will execute the tests that you loaded on the hub.

What is node in Selenium grid?

A Selenium Grid has only one Hub and it is launched on a single machine once. Node − Nodes are the Selenium instances that are attached to the Hub which execute the tests. There can be one or more nodes in a grid which can be of any OS and can contain any of the Selenium supported browsers.


1 Answers

Since you are running the grid (and potentially Jenkins/eclipse) from the Hub machine, system.getenv() will return information from the hub machine and not the node machines.

With Selenium Grid 2, it is pretty simple to get the node name, follow these steps:

  1. Get the session id from your webdriver.
Webdriver.getSessionId();
  1. Goto the below url.

    Replace gridIP with IP or hostname of your Grid's hub machine.

    Replace mySessionId with session Id that you got from step 1 above.

http://gridIP:4444/grid/api/testsession?session=mySessionId
  1. From the JSON response you can find IP and port number from proxyId field.

    Sample JSON response below (see proxyId at the very end):

{"msg":"slot found !","success":true,"session":"xd1215w5-sw53-4bcc-qwa6-7e1214dd6542","internalKey":"q13b2q5x-a21s-5ggt-b6aw-1w1qzr5k0672","inactivityTime":78,"proxyId":"http://10.10.9.3:7777"}
  1. Here is the IP address where current test was/is executed.
"proxyId":"http://10.10.9.3:7777"
like image 86
Nash N Avatar answered Oct 21 '22 01:10

Nash N