Selenium 2 Grid - Knowing which node your test is using

前端 未结 2 959
無奈伤痛
無奈伤痛 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: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]);
    

提交回复
热议问题