Selenium 2 Grid - Knowing which node your test is using

空扰寡人 提交于 2019-11-30 06:51:28

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.

Harshavardhan Konakanchi
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]);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!