Skip to content

Commit 788936f

Browse files
committed
Remove requiredCapabilities from ProtocolHandshake
1 parent 456d9f0 commit 788936f

File tree

2 files changed

+15
-43
lines changed

2 files changed

+15
-43
lines changed

java/client/src/org/openqa/selenium/remote/ProtocolHandshake.java

+15-40
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import com.google.gson.JsonElement;
3838
import com.google.gson.JsonObject;
3939
import com.google.gson.JsonPrimitive;
40-
import com.google.gson.reflect.TypeToken;
4140
import com.google.gson.stream.JsonWriter;
4241

4342
import org.openqa.selenium.Capabilities;
@@ -54,7 +53,6 @@
5453
import java.io.BufferedWriter;
5554
import java.io.IOException;
5655
import java.io.InputStream;
57-
import java.lang.reflect.Type;
5856
import java.nio.file.Files;
5957
import java.nio.file.Path;
6058
import java.util.Collection;
@@ -96,12 +94,9 @@ public Result createSession(HttpClient client, Command command)
9694
throws IOException {
9795
Capabilities desired = (Capabilities) command.getParameters().get("desiredCapabilities");
9896
desired = desired == null ? new ImmutableCapabilities() : desired;
99-
Capabilities required = (Capabilities) command.getParameters().get("requiredCapabilities");
100-
required = required == null ? new ImmutableCapabilities() : required;
10197

10298
BeanToJsonConverter converter = new BeanToJsonConverter();
10399
JsonObject des = (JsonObject) converter.convertObject(desired);
104-
JsonObject req = (JsonObject) converter.convertObject(required);
105100

106101
// We don't know how large the generated JSON is going to be. Spool it to disk, and then read
107102
// 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)
116111
Gson gson = new Gson();
117112
out.beginObject();
118113

119-
streamJsonWireProtocolParameters(out, gson, des, req);
114+
streamJsonWireProtocolParameters(out, gson, des);
120115

121116
out.name("capabilities");
122117
out.beginObject();
123-
streamGeckoDriver013Parameters(out, gson, des, req);
124-
streamW3CProtocolParameters(out, gson, des, req);
118+
streamGeckoDriver013Parameters(out, gson, des);
119+
streamW3CProtocolParameters(out, gson, des);
125120
out.endObject();
126121

127122
out.endObject();
@@ -146,27 +141,22 @@ public Result createSession(HttpClient client, Command command)
146141
throw new SessionNotCreatedException(
147142
String.format(
148143
"Unable to create new remote session. " +
149-
"desired capabilities = %s, required capabilities = %s",
150-
desired,
151-
required));
144+
"desired capabilities = %s",
145+
desired));
152146
}
153147

154148
private void streamJsonWireProtocolParameters(
155149
JsonWriter out,
156150
Gson gson,
157-
JsonObject des,
158-
JsonObject req) throws IOException {
151+
JsonObject des) throws IOException {
159152
out.name("desiredCapabilities");
160153
gson.toJson(des, out);
161-
out.name("requiredCapabilities");
162-
gson.toJson(req, out);
163154
}
164155

165156
private void streamW3CProtocolParameters(
166157
JsonWriter out,
167158
Gson gson,
168-
JsonObject des,
169-
JsonObject req) throws IOException {
159+
JsonObject des) throws IOException {
170160
// Technically we should be building up a combination of "alwaysMatch" and "firstMatch" options.
171161
// We're going to do a little processing to figure out what we might be able to do, and assume
172162
// that people don't really understand the difference between required and desired (which is
@@ -187,35 +177,27 @@ private void streamW3CProtocolParameters(
187177
// We can't use the constants defined in the classes because it would introduce circular
188178
// dependencies between the remote library and the implementations. Yay!
189179

190-
Map<String, ?> chrome = Stream.of(des, req)
191-
.map(JsonObject::entrySet)
192-
.flatMap(Collection::stream)
180+
Map<String, ?> chrome = des.entrySet().stream()
193181
.filter(entry ->
194182
("browserName".equals(entry.getKey()) && CHROME.equals(entry.getValue().getAsString())) ||
195183
"chromeOptions".equals(entry.getKey()))
196184
.distinct()
197185
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (left, right) -> right));
198186

199-
Map<String, ?> edge = Stream.of(des, req)
200-
.map(JsonObject::entrySet)
201-
.flatMap(Collection::stream)
187+
Map<String, ?> edge = des.entrySet().stream()
202188
.filter(entry -> ("browserName".equals(entry.getKey()) && EDGE.equals(entry.getValue().getAsString())))
203189
.distinct()
204190
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (left, right) -> right));
205191

206-
Map<String, ?> firefox = Stream.of(des, req)
207-
.map(JsonObject::entrySet)
208-
.flatMap(Collection::stream)
192+
Map<String, ?> firefox = des.entrySet().stream()
209193
.filter(entry ->
210194
("browserName".equals(entry.getKey()) && FIREFOX.equals(entry.getValue().getAsString())) ||
211195
entry.getKey().startsWith("firefox_") ||
212196
entry.getKey().startsWith("moz:"))
213197
.distinct()
214198
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (left, right) -> right));
215199

216-
Map<String, ?> ie = Stream.of(req, des)
217-
.map(JsonObject::entrySet)
218-
.flatMap(Collection::stream)
200+
Map<String, ?> ie = des.entrySet().stream()
219201
.filter(entry ->
220202
("browserName".equals(entry.getKey()) && IE.equals(entry.getValue().getAsString())) ||
221203
"browserAttachTimeout".equals(entry.getKey()) ||
@@ -234,19 +216,15 @@ private void streamW3CProtocolParameters(
234216
.distinct()
235217
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (left, right) -> right));
236218

237-
Map<String, ?> opera = Stream.of(des, req)
238-
.map(JsonObject::entrySet)
239-
.flatMap(Collection::stream)
219+
Map<String, ?> opera = des.entrySet().stream()
240220
.filter(entry ->
241221
("browserName".equals(entry.getKey()) && OPERA_BLINK.equals(entry.getValue().getAsString())) ||
242222
("browserName".equals(entry.getKey()) && OPERA.equals(entry.getValue().getAsString())) ||
243223
"operaOptions".equals(entry.getKey()))
244224
.distinct()
245225
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (left, right) -> right));
246226

247-
Map<String, ?> safari = Stream.of(des, req)
248-
.map(JsonObject::entrySet)
249-
.flatMap(Collection::stream)
227+
Map<String, ?> safari = des.entrySet().stream()
250228
.filter(entry ->
251229
("browserName".equals(entry.getKey()) && SAFARI.equals(entry.getValue().getAsString())) ||
252230
"safari.options".equals(entry.getKey()))
@@ -259,7 +237,7 @@ private void streamW3CProtocolParameters(
259237
.distinct()
260238
.collect(ImmutableSet.toImmutableSet());
261239

262-
JsonObject alwaysMatch = Stream.of(des, req)
240+
JsonObject alwaysMatch = Stream.of(des)
263241
.map(JsonObject::entrySet)
264242
.flatMap(Collection::stream)
265243
.filter(entry -> !excludedKeys.contains(entry.getKey()))
@@ -363,12 +341,9 @@ public Optional<Result> createSession(HttpClient client, InputStream newSessionB
363341
private void streamGeckoDriver013Parameters(
364342
JsonWriter out,
365343
Gson gson,
366-
JsonObject des,
367-
JsonObject req) throws IOException {
344+
JsonObject des) throws IOException {
368345
out.name("desiredCapabilities");
369346
gson.toJson(des, out);
370-
out.name("requiredCapabilities");
371-
gson.toJson(req, out);
372347
}
373348

374349
public static class Result {

java/client/test/org/openqa/selenium/remote/ProtocolHandshakeTest.java

-3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ public void requestShouldIncludeJsonWireProtocolCapabilities() throws IOExceptio
7676
.fromJson(request.getContentString(), new TypeToken<Map<String, Object>>(){}.getType());
7777

7878
assertEquals(ImmutableMap.of(), json.get("desiredCapabilities"));
79-
assertEquals(ImmutableMap.of(), json.get("requiredCapabilities"));
8079
}
8180

8281
@Test
@@ -98,7 +97,6 @@ public void requestShouldIncludeOlderGeckoDriverCapabilities() throws IOExceptio
9897
Map<String, Object> capabilities = (Map<String, Object>) json.get("capabilities");
9998

10099
assertEquals(ImmutableMap.of(), capabilities.get("desiredCapabilities"));
101-
assertEquals(ImmutableMap.of(), capabilities.get("requiredCapabilities"));
102100
}
103101

104102
@Test
@@ -197,7 +195,6 @@ public void shouldAddBothGeckoDriverAndW3CCapabilitiesToRootCapabilitiesProperty
197195

198196
// GeckoDriver
199197
assertTrue(capabilities.containsKey("desiredCapabilities"));
200-
assertTrue(capabilities.containsKey("requiredCapabilities"));
201198

202199
// W3C
203200
assertTrue(capabilities.containsKey("alwaysMatch"));

0 commit comments

Comments
 (0)