Example usage for org.openqa.selenium.remote Command getParameters

List of usage examples for org.openqa.selenium.remote Command getParameters

Introduction

In this page you can find the example usage for org.openqa.selenium.remote Command getParameters.

Prototype

public Map<String, ?> getParameters() 

Source Link

Usage

From source file:com.jobaline.uiautomation.framework.selenium.phantomJsThreeHourTimeoutFix.HttpCommandExecutor.java

License:Apache License

public Response execute(Command command) throws IOException {
    HttpContext context = new BasicHttpContext();

    if (command.getSessionId() == null) {
        if (QUIT.equals(command.getName())) {
            return new Response();
        }// w  ww. j  av a  2 s  .  c om
        if (!GET_ALL_SESSIONS.equals(command.getName()) && !NEW_SESSION.equals(command.getName())) {
            throw new SessionNotFoundException("Session ID is null. Using WebDriver after calling quit()?");
        }
    }

    CommandInfo info = nameToUrl.get(command.getName());
    try {
        HttpUriRequest httpMethod = info.getMethod(remoteServer, command);

        setAcceptHeader(httpMethod);

        if (httpMethod instanceof HttpPost) {
            String payload = new BeanToJsonConverter().convert(command.getParameters());
            ((HttpPost) httpMethod).setEntity(new StringEntity(payload, "utf-8"));
            httpMethod.addHeader("Content-Type", "application/json; charset=utf-8");
        }

        // Do not allow web proxy caches to cache responses to "get" commands
        if (httpMethod instanceof HttpGet) {
            httpMethod.addHeader("Cache-Control", "no-cache");
        }

        log(LogType.PROFILER, new HttpProfilerLogEntry(command.getName(), true));
        HttpResponse response = fallBackExecute(context, httpMethod);
        log(LogType.PROFILER, new HttpProfilerLogEntry(command.getName(), false));

        response = followRedirects(client, context, response, /* redirect count */0);

        final EntityWithEncoding entityWithEncoding = new EntityWithEncoding(response.getEntity());

        return createResponse(response, context, entityWithEncoding);
    } catch (UnsupportedCommandException e) {
        if (e.getMessage() == null || "".equals(e.getMessage())) {
            throw new UnsupportedOperationException(
                    "No information from server. Command name was: " + command.getName(), e.getCause());
        }
        throw e;
    }
}

From source file:io.appium.java_client.remote.AppiumProtocolHandShake.java

License:Apache License

public Result createSession(HttpClient client, Command command) throws IOException, WebDriverException {

    Capabilities desired = ofNullable((Capabilities) command.getParameters().get("desiredCapabilities"))
            .orElseGet(DesiredCapabilities::new);

    Capabilities required = ofNullable((Capabilities) command.getParameters().get("requiredCapabilities"))
            .orElseGet(DesiredCapabilities::new);

    JsonParser parser = new JsonParser();
    JsonElement des = parser.parse(new BeanToJsonConverter().convert(desired));
    JsonElement req = parser.parse(new BeanToJsonConverter().convert(required));

    JsonObject jsonObject = new JsonObject();

    amendW3CParameters(jsonObject, des, req);
    amendOssParamters(jsonObject, des, req);
    Optional<Result> result = createSession(client, jsonObject);

    return ofNullable(result.orElseGet(() -> {
        JsonObject jsonObject1 = new JsonObject();
        amendOssParamters(jsonObject1, des, req);

        try {/*from  w  ww .  ja  v  a2 s.  co m*/
            return createSession(client, jsonObject1).orElseGet(() -> {
                JsonObject jsonObject2 = new JsonObject();
                amendW3CParameters(jsonObject2, des, req);

                try {
                    return createSession(client, jsonObject2).orElse(null);
                } catch (IOException e) {
                    throw new WebDriverException(e);
                }
            });
        } catch (IOException e) {
            throw new WebDriverException(e);
        }
    })).orElseThrow(() -> new SessionNotCreatedException(String.format(
            "Unable to create new remote session. " + "desired capabilities = %s, required capabilities = %s",
            desired, required)));
}