List of usage examples for org.openqa.selenium.remote Dialect OSS
Dialect OSS
To view the source code for org.openqa.selenium.remote Dialect OSS.
Click Source Link
From source file:com.google.testing.web.screenshotter.Screenshotter.java
License:Apache License
private static JSONObject webElementToJSON(WebElement element) throws JSONException { String id = ((RemoteWebElement) element).getId(); JSONObject object = new JSONObject(); object.put(Dialect.OSS.getEncodedElementKey(), id); object.put(Dialect.W3C.getEncodedElementKey(), id); return object; }
From source file:io.appium.java_client.remote.AppiumProtocolHandShake.java
License:Apache License
private Optional<Result> createSession(HttpClient client, JsonObject params) throws IOException { // Create the http request and send it HttpRequest request = new HttpRequest(HttpMethod.POST, "/session"); String content = params.toString(); byte[] data = content.getBytes(UTF_8); request.setHeader(CONTENT_LENGTH, String.valueOf(data.length)); request.setHeader(CONTENT_TYPE, JSON_UTF_8.toString()); request.setContent(data);//from w w w . j ava 2s . c o m HttpResponse response = client.execute(request, true); Map<?, ?> jsonBlob = new HashMap<>(); String resultString = response.getContentString(); try { jsonBlob = new JsonToBeanConverter().convert(Map.class, resultString); } catch (ClassCastException e) { return Optional.empty(); } catch (JsonException e) { // Fine. Handle that below } // If the result looks positive, return the result. Object sessionId = jsonBlob.get("sessionId"); Object value = jsonBlob.get("value"); Object w3cError = jsonBlob.get("error"); Object ossStatus = jsonBlob.get("status"); Map<String, ?> capabilities = null; if (value != null && value instanceof Map) { capabilities = (Map<String, ?>) value; } else if (value != null && value instanceof Capabilities) { capabilities = ((Capabilities) capabilities).asMap(); } if (response.getStatus() == HttpURLConnection.HTTP_OK && sessionId != null && capabilities != null) { Dialect dialect = ossStatus == null ? Dialect.W3C : Dialect.OSS; return Optional.of(new Result(dialect, String.valueOf(sessionId), capabilities)); } // If the result was an error that we believe has to do with the remote end failing to start the // session, create an exception and throw it. Response tempResponse = null; if ("session not created".equals(w3cError)) { tempResponse = new Response(null); tempResponse.setStatus(SESSION_NOT_CREATED); tempResponse.setValue(jsonBlob); } else if (ossStatus instanceof Number && ((Number) ossStatus).intValue() == SESSION_NOT_CREATED) { tempResponse = new Response(null); tempResponse.setStatus(SESSION_NOT_CREATED); tempResponse.setValue(jsonBlob); } if (tempResponse != null) { new ErrorHandler().throwIfResponseFailed(tempResponse, 0); } // Otherwise, just return empty. return Optional.empty(); }
From source file:io.appium.java_client.remote.NewAppiumSessionPayload.java
License:Apache License
private NewAppiumSessionPayload(Reader source, boolean forceMobileJSONWP) throws IOException { this.forceMobileJSONWP = forceMobileJSONWP; // Dedicate up to 10% of all RAM or 20% of available RAM (whichever is smaller) to storing this // payload./*from www . ja v a2s. co m*/ int threshold = (int) Math.min(Integer.MAX_VALUE, Math.min(Runtime.getRuntime().freeMemory() / 5, Runtime.getRuntime().maxMemory() / 10)); backingStore = new FileBackedOutputStream(threshold); try (Writer writer = new OutputStreamWriter(backingStore, UTF_8)) { CharStreams.copy(source, writer); } ImmutableSet.Builder<CapabilitiesFilter> adapters = ImmutableSet.builder(); ServiceLoader.load(CapabilitiesFilter.class).forEach(adapters::add); adapters.add(new ChromeFilter()).add(new EdgeFilter()).add(new FirefoxFilter()) .add(new InternetExplorerFilter()).add(new OperaFilter()).add(new SafariFilter()); this.adapters = adapters.build(); ImmutableSet.Builder<CapabilityTransform> transforms = ImmutableSet.builder(); ServiceLoader.load(CapabilityTransform.class).forEach(transforms::add); transforms.add(new ProxyTransform()).add(new StripAnyPlatform()).add(new W3CPlatformNameNormaliser()); this.transforms = transforms.build(); ImmutableSet.Builder<Dialect> dialects = ImmutableSet.builder(); if (getOss() != null) { dialects.add(Dialect.OSS); } if (getAlwaysMatch() != null || getFirstMatch() != null) { dialects.add(Dialect.W3C); } validate(); }