Selenium 2 Grid - Knowing which node your test is using
Asked Answered
H

2

13

Is it possible to know which node the selenium grid hub assigned to your test? My tests need to talk to other services on the node machine in order to perform configurations which are not supported by selenium.

Mark

Huelva answered 1/8, 2011 at 12:58 Comment(0)
S
8

Generally you shouldn't rely on knowing what machine your test is running on. Grid 2 provides a series of callback listeners that you could implement to provide machine configuration. But, if you really want to see what node a test is running on, you could use one of the API calls. Both endpoints can be found on the hub:

http://localhost:4444/grid/api/proxy

http://localhost:4444/grid/api/testsession

Neither are documented yet. But if you view the source, it's straightforward to see how they work. You want to look at the ProxyStatusServlet and TestSessionStatusServlet.

Sole answered 1/8, 2011 at 13:16 Comment(3)
Thank you nirvdrum. I'll have a look at the code. Are the callback listeners you mentioned documented somewhere by any chance?Huelva
Unfortunately, not yet. But if you look at the JavaDocs for the classes in the org.openqa.grid.internal.listeners package, you should be able to get going. Grid also internally uses these listeners to perform much of its work, so there are concrete implementations you can look at. Any help you could provide with the docs would be much appreciated, too :-)Sole
I'm extremly busy till early October but would love to help out after that.Huelva
Z
3
String hub = "grid_server_host"; //IP or hostname of GRID

int port = 4444; // port no.

HttpHost host = new HttpHost(hub,port);

DefaultHttpClient client = new DefaultHttpClient();

String url =  host + "/grid/api/testsession?session=";

URL session = new URL(url + ((RemoteWebDriver) webdriver).getSessionId());

BasicHttpEntityEnclosingRequest req;

req = new BasicHttpEntityEnclosingRequest("POST", session.toExternalForm());

org.apache.http.HttpResponse response  = client.execute(host,req);

JSONObject object = new JSONObject(EntityUtils.toString(response.getEntity()));   

String proxyID = (String) object.get("proxyId");

String node = (proxyID.split("//")[1].split(":")[0]);
Zicarelli answered 20/2, 2013 at 6:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.