Thursday, 15 February 2018

Selenium Grid -> Get Node Ip address

public  void getNodeIpAddress(){
        try {
            URL url = new URL("http://hub-ip:4444//grid/api/testsession?session="+((RemoteWebDriver) driver).getSessionId().toString());
            BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", url.toExternalForm());
            DefaultHttpClient client = new DefaultHttpClient();
            HttpHost host = new HttpHost(url.getHost(), url.getPort());
            HttpResponse response = client.execute(host, request);           
            String responseBody=EntityUtils.toString(response.getEntity());
            System.out.println(responseBody);
//Here you can find ip addr of the node machine at ProxyId parameter
            //  URL nodeUrl = new URL(object.getString("proxyId"));
            //return nodeUrl.getHost();
        } catch (Exception e){
        }

No comments:

Post a Comment