Selenium 2 Grid - Knowing which node your test is using

隐身守侯 提交于 2019-12-18 12:26:55

问题


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


回答1:


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.




回答2:


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]);


来源:https://stackoverflow.com/questions/6898735/selenium-2-grid-knowing-which-node-your-test-is-using

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