Selenium 2 Grid - Knowing which node your test is using

前端 未结 2 958
無奈伤痛
無奈伤痛 2020-12-30 06:24

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 configuration

相关标签:
2条回答
  • 2020-12-30 07:05

    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.

    0 讨论(0)
  • 2020-12-30 07:07
    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]);
    
    0 讨论(0)
提交回复
热议问题