use of org.openqa.selenium.remote.SessionId in project cerberus-source by cerberustesting.
the class SeleniumServerService method getIPOfNode.
private static void getIPOfNode(TestCaseExecution tCExecution) {
try {
Session session = tCExecution.getSession();
HttpCommandExecutor ce = (HttpCommandExecutor) ((RemoteWebDriver) session.getDriver()).getCommandExecutor();
SessionId sessionId = ((RemoteWebDriver) session.getDriver()).getSessionId();
String hostName = ce.getAddressOfRemoteServer().getHost();
int port = ce.getAddressOfRemoteServer().getPort();
HttpHost host = new HttpHost(hostName, port);
HttpClient client = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();
URL sessionURL = new URL(SeleniumServerService.getBaseUrl(session.getHost(), session.getPort()) + "/grid/api/testsession?session=" + sessionId);
BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST", sessionURL.toExternalForm());
HttpResponse response = client.execute(host, r);
if (!response.getStatusLine().toString().contains("403") && !response.getEntity().getContentType().getValue().contains("text/html")) {
InputStream contents = response.getEntity().getContent();
StringWriter writer = new StringWriter();
IOUtils.copy(contents, writer, "UTF8");
JSONObject object = new JSONObject(writer.toString());
URL myURL = new URL(object.getString("proxyId"));
if ((myURL.getHost() != null) && (myURL.getPort() != -1)) {
tCExecution.setIp(myURL.getHost());
tCExecution.setPort(String.valueOf(myURL.getPort()));
}
}
} catch (IOException ex) {
LOG.error(ex.toString());
} catch (JSONException ex) {
LOG.error(ex.toString());
}
}
Aggregations