Example usage for org.openqa.selenium.remote HttpCommandExecutor getAddressOfRemoteServer

List of usage examples for org.openqa.selenium.remote HttpCommandExecutor getAddressOfRemoteServer

Introduction

In this page you can find the example usage for org.openqa.selenium.remote HttpCommandExecutor getAddressOfRemoteServer.

Prototype

public URL getAddressOfRemoteServer() 

Source Link

Usage

From source file:com.mengge.AppiumDriver.java

License:Apache License

/**
 * @param executor is an instance of {@link org.openqa.selenium.remote.HttpCommandExecutor}
 *                 or class that extends it. Default commands or another vendor-specific
 *                 commands may be specified there.
 * @param capabilities take a look// w w w  . j  a va  2s.  c om
 *                     at {@link org.openqa.selenium.Capabilities}
 * @param converterClazz is an instance of a class that extends
 * {@link org.openqa.selenium.remote.internal.JsonToWebElementConverter}. It converts
 *                       JSON response to an instance of
 *                       {@link org.openqa.selenium.WebElement}
 */
protected AppiumDriver(HttpCommandExecutor executor, Capabilities capabilities,
        Class<? extends JsonToWebElementConverter> converterClazz) {
    super(executor, capabilities);
    this.executeMethod = new AppiumExecutionMethod(this);
    locationContext = new RemoteLocationContext(executeMethod);
    super.setErrorHandler(errorHandler);
    this.remoteAddress = executor.getAddressOfRemoteServer();
    try {
        Constructor<? extends JsonToWebElementConverter> constructor = converterClazz
                .getConstructor(RemoteWebDriver.class);
        this.setElementConverter(constructor.newInstance(this));
    } catch (NoSuchMethodException | IllegalAccessException | InstantiationException
            | InvocationTargetException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.vaadin.tests.elements.AbstractTB3Test.java

License:Apache License

protected String getRemoteControlName() {
    try {/*from   www .j  ava2 s  .c  o m*/
        RemoteWebDriver d = getRemoteDriver();
        if (d == null) {
            return null;
        }
        HttpCommandExecutor ce = (HttpCommandExecutor) d.getCommandExecutor();
        String hostName = ce.getAddressOfRemoteServer().getHost();
        int port = ce.getAddressOfRemoteServer().getPort();
        HttpHost host = new HttpHost(hostName, port);
        DefaultHttpClient client = new DefaultHttpClient();
        URL sessionURL = new URL(
                "http://" + hostName + ":" + port + "/grid/api/testsession?session=" + d.getSessionId());
        BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST",
                sessionURL.toExternalForm());
        HttpResponse response = client.execute(host, r);
        JsonObject object = extractObject(response);
        URL myURL = new URL(object.get("proxyId").getAsString());
        if ((myURL.getHost() != null) && (myURL.getPort() != -1)) {
            return myURL.getHost();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.cerberus.engine.execution.impl.SeleniumServerService.java

License:Open Source License

private static void getIPOfNode(TestCaseExecution tCExecution) {
    try {/*from  w  w  w.j ava2s  .co m*/
        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().build();
        URL sessionURL = new URL("http://" + 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")) {
            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());
    }
}

From source file:org.cerberus.service.engine.impl.SeleniumServerService.java

License:Open Source License

private static void getIPOfNode(TestCaseExecution tCExecution) {
    try {/*from w w w .ja v  a 2  s . c o m*/
        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().build();
        URL sessionURL = new URL("http://" + 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")) {
            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) {
        Logger.getLogger(SeleniumServerService.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (JSONException ex) {
        Logger.getLogger(SeleniumServerService.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
}