RemoteWebDriver and Grid - is it possible to get the IP address of the server?

I use Selenium 2 and Grid's RemoteWebDriver to share my tests on multiple virtual machines. Let's say I have two Linux machines, and in the test I indicate the possibility of running on a Linux machine, I can’t understand which of these two machines is used. Is there any way to figure this out? Something like driver.getServerIp () or something else? The reason is that in my Selenium test code I want to run a bash script on the console of the Linux machine where the testing is being performed. So I need to know which machine passes the test.

Thanks guys!

+4
source share
3 answers

My java skills are not the biggest, and this code may use some cleanup, but this works for me.

HttpHost host = new HttpHost(yourHubIP, yourHubPort); DefaultHttpClient client = new DefaultHttpClient(); URL testSessionApi = new URL("http://" + yourHubIP + ":" + yourHubPort + "/grid/api/testsession?session=" + driver.getSessionId()); BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST", testSessionApi.toExternalForm()); HttpResponse response = client.execute(host,r); JSONObject object = (JSONObject)new JSONParser().parse(EntityUtils.toString(response.getEntity())); String proxyID = object.get("proxyId")); 

proxyID contains the IP address of node.

+4
source
 HttpCommandExecutor ce = (HttpCommandExecutor) ((RemoteWebDriver)driver).getCommandExecutor(); ce.getAddressOfRemoteServer(); 

Although you probably know the address, since you still passed it to the constructor for RemoteWebDriver.

+1
source

The answer provided by Bobble D only works with the fact that the problem with JSONParser, as Nilesh is also mentioned, here is updated code that can help

 HttpHost host = new HttpHost(yourHubIP, yourHubPort); DefaultHttpClient client = new DefaultHttpClient(); URL testSessionApi = new URL("http://" + yourHubIP + ":" + yourHubPort + "/grid/api/testsession?session=" + ((RemoteWebDriver) driver).getSessionId()); BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST", testSessionApi.toExternalForm()); HttpResponse response = client.execute(host,r); JSONObject object = new JSONObject(EntityUtils.toString(response.getEntity())); String proxyID = object.get("proxyId")); System.out.println(proxyID.split("//")[1].split(":")[0]); 
+1
source

Source: https://habr.com/ru/post/1368948/


All Articles