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 ma开发者_如何学JAVAchine in order to perform configurations which are not supported by selenium.
Mark
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.
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]);
精彩评论