From 788936fa0597d0755185fa89566381d9555bf5a4 Mon Sep 17 00:00:00 2001 From: Simon Stewart Date: Tue, 3 Oct 2017 16:58:28 +0100 Subject: [PATCH] Remove requiredCapabilities from ProtocolHandshake --- .../selenium/remote/ProtocolHandshake.java | 55 +++++-------------- .../remote/ProtocolHandshakeTest.java | 3 - 2 files changed, 15 insertions(+), 43 deletions(-) diff --git a/java/client/src/org/openqa/selenium/remote/ProtocolHandshake.java b/java/client/src/org/openqa/selenium/remote/ProtocolHandshake.java index 6687c89ba61ec..f262afbfacd42 100644 --- a/java/client/src/org/openqa/selenium/remote/ProtocolHandshake.java +++ b/java/client/src/org/openqa/selenium/remote/ProtocolHandshake.java @@ -37,7 +37,6 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; -import com.google.gson.reflect.TypeToken; import com.google.gson.stream.JsonWriter; import org.openqa.selenium.Capabilities; @@ -54,7 +53,6 @@ import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; -import java.lang.reflect.Type; import java.nio.file.Files; import java.nio.file.Path; import java.util.Collection; @@ -96,12 +94,9 @@ public Result createSession(HttpClient client, Command command) throws IOException { Capabilities desired = (Capabilities) command.getParameters().get("desiredCapabilities"); desired = desired == null ? new ImmutableCapabilities() : desired; - Capabilities required = (Capabilities) command.getParameters().get("requiredCapabilities"); - required = required == null ? new ImmutableCapabilities() : required; BeanToJsonConverter converter = new BeanToJsonConverter(); JsonObject des = (JsonObject) converter.convertObject(desired); - JsonObject req = (JsonObject) converter.convertObject(required); // We don't know how large the generated JSON is going to be. Spool it to disk, and then read // the file size, then stream it to the remote end. If we could be sure the remote end could @@ -116,12 +111,12 @@ public Result createSession(HttpClient client, Command command) Gson gson = new Gson(); out.beginObject(); - streamJsonWireProtocolParameters(out, gson, des, req); + streamJsonWireProtocolParameters(out, gson, des); out.name("capabilities"); out.beginObject(); - streamGeckoDriver013Parameters(out, gson, des, req); - streamW3CProtocolParameters(out, gson, des, req); + streamGeckoDriver013Parameters(out, gson, des); + streamW3CProtocolParameters(out, gson, des); out.endObject(); out.endObject(); @@ -146,27 +141,22 @@ public Result createSession(HttpClient client, Command command) throw new SessionNotCreatedException( String.format( "Unable to create new remote session. " + - "desired capabilities = %s, required capabilities = %s", - desired, - required)); + "desired capabilities = %s", + desired)); } private void streamJsonWireProtocolParameters( JsonWriter out, Gson gson, - JsonObject des, - JsonObject req) throws IOException { + JsonObject des) throws IOException { out.name("desiredCapabilities"); gson.toJson(des, out); - out.name("requiredCapabilities"); - gson.toJson(req, out); } private void streamW3CProtocolParameters( JsonWriter out, Gson gson, - JsonObject des, - JsonObject req) throws IOException { + JsonObject des) throws IOException { // Technically we should be building up a combination of "alwaysMatch" and "firstMatch" options. // We're going to do a little processing to figure out what we might be able to do, and assume // that people don't really understand the difference between required and desired (which is @@ -187,25 +177,19 @@ private void streamW3CProtocolParameters( // We can't use the constants defined in the classes because it would introduce circular // dependencies between the remote library and the implementations. Yay! - Map chrome = Stream.of(des, req) - .map(JsonObject::entrySet) - .flatMap(Collection::stream) + Map chrome = des.entrySet().stream() .filter(entry -> ("browserName".equals(entry.getKey()) && CHROME.equals(entry.getValue().getAsString())) || "chromeOptions".equals(entry.getKey())) .distinct() .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (left, right) -> right)); - Map edge = Stream.of(des, req) - .map(JsonObject::entrySet) - .flatMap(Collection::stream) + Map edge = des.entrySet().stream() .filter(entry -> ("browserName".equals(entry.getKey()) && EDGE.equals(entry.getValue().getAsString()))) .distinct() .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (left, right) -> right)); - Map firefox = Stream.of(des, req) - .map(JsonObject::entrySet) - .flatMap(Collection::stream) + Map firefox = des.entrySet().stream() .filter(entry -> ("browserName".equals(entry.getKey()) && FIREFOX.equals(entry.getValue().getAsString())) || entry.getKey().startsWith("firefox_") || @@ -213,9 +197,7 @@ private void streamW3CProtocolParameters( .distinct() .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (left, right) -> right)); - Map ie = Stream.of(req, des) - .map(JsonObject::entrySet) - .flatMap(Collection::stream) + Map ie = des.entrySet().stream() .filter(entry -> ("browserName".equals(entry.getKey()) && IE.equals(entry.getValue().getAsString())) || "browserAttachTimeout".equals(entry.getKey()) || @@ -234,9 +216,7 @@ private void streamW3CProtocolParameters( .distinct() .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (left, right) -> right)); - Map opera = Stream.of(des, req) - .map(JsonObject::entrySet) - .flatMap(Collection::stream) + Map opera = des.entrySet().stream() .filter(entry -> ("browserName".equals(entry.getKey()) && OPERA_BLINK.equals(entry.getValue().getAsString())) || ("browserName".equals(entry.getKey()) && OPERA.equals(entry.getValue().getAsString())) || @@ -244,9 +224,7 @@ private void streamW3CProtocolParameters( .distinct() .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (left, right) -> right)); - Map safari = Stream.of(des, req) - .map(JsonObject::entrySet) - .flatMap(Collection::stream) + Map safari = des.entrySet().stream() .filter(entry -> ("browserName".equals(entry.getKey()) && SAFARI.equals(entry.getValue().getAsString())) || "safari.options".equals(entry.getKey())) @@ -259,7 +237,7 @@ private void streamW3CProtocolParameters( .distinct() .collect(ImmutableSet.toImmutableSet()); - JsonObject alwaysMatch = Stream.of(des, req) + JsonObject alwaysMatch = Stream.of(des) .map(JsonObject::entrySet) .flatMap(Collection::stream) .filter(entry -> !excludedKeys.contains(entry.getKey())) @@ -363,12 +341,9 @@ public Optional createSession(HttpClient client, InputStream newSessionB private void streamGeckoDriver013Parameters( JsonWriter out, Gson gson, - JsonObject des, - JsonObject req) throws IOException { + JsonObject des) throws IOException { out.name("desiredCapabilities"); gson.toJson(des, out); - out.name("requiredCapabilities"); - gson.toJson(req, out); } public static class Result { diff --git a/java/client/test/org/openqa/selenium/remote/ProtocolHandshakeTest.java b/java/client/test/org/openqa/selenium/remote/ProtocolHandshakeTest.java index 0555ad3d9f437..81e3907e885c6 100644 --- a/java/client/test/org/openqa/selenium/remote/ProtocolHandshakeTest.java +++ b/java/client/test/org/openqa/selenium/remote/ProtocolHandshakeTest.java @@ -76,7 +76,6 @@ public void requestShouldIncludeJsonWireProtocolCapabilities() throws IOExceptio .fromJson(request.getContentString(), new TypeToken>(){}.getType()); assertEquals(ImmutableMap.of(), json.get("desiredCapabilities")); - assertEquals(ImmutableMap.of(), json.get("requiredCapabilities")); } @Test @@ -98,7 +97,6 @@ public void requestShouldIncludeOlderGeckoDriverCapabilities() throws IOExceptio Map capabilities = (Map) json.get("capabilities"); assertEquals(ImmutableMap.of(), capabilities.get("desiredCapabilities")); - assertEquals(ImmutableMap.of(), capabilities.get("requiredCapabilities")); } @Test @@ -197,7 +195,6 @@ public void shouldAddBothGeckoDriverAndW3CCapabilitiesToRootCapabilitiesProperty // GeckoDriver assertTrue(capabilities.containsKey("desiredCapabilities")); - assertTrue(capabilities.containsKey("requiredCapabilities")); // W3C assertTrue(capabilities.containsKey("alwaysMatch"));