37
37
import com .google .gson .JsonElement ;
38
38
import com .google .gson .JsonObject ;
39
39
import com .google .gson .JsonPrimitive ;
40
- import com .google .gson .reflect .TypeToken ;
41
40
import com .google .gson .stream .JsonWriter ;
42
41
43
42
import org .openqa .selenium .Capabilities ;
54
53
import java .io .BufferedWriter ;
55
54
import java .io .IOException ;
56
55
import java .io .InputStream ;
57
- import java .lang .reflect .Type ;
58
56
import java .nio .file .Files ;
59
57
import java .nio .file .Path ;
60
58
import java .util .Collection ;
@@ -96,12 +94,9 @@ public Result createSession(HttpClient client, Command command)
96
94
throws IOException {
97
95
Capabilities desired = (Capabilities ) command .getParameters ().get ("desiredCapabilities" );
98
96
desired = desired == null ? new ImmutableCapabilities () : desired ;
99
- Capabilities required = (Capabilities ) command .getParameters ().get ("requiredCapabilities" );
100
- required = required == null ? new ImmutableCapabilities () : required ;
101
97
102
98
BeanToJsonConverter converter = new BeanToJsonConverter ();
103
99
JsonObject des = (JsonObject ) converter .convertObject (desired );
104
- JsonObject req = (JsonObject ) converter .convertObject (required );
105
100
106
101
// We don't know how large the generated JSON is going to be. Spool it to disk, and then read
107
102
// 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)
116
111
Gson gson = new Gson ();
117
112
out .beginObject ();
118
113
119
- streamJsonWireProtocolParameters (out , gson , des , req );
114
+ streamJsonWireProtocolParameters (out , gson , des );
120
115
121
116
out .name ("capabilities" );
122
117
out .beginObject ();
123
- streamGeckoDriver013Parameters (out , gson , des , req );
124
- streamW3CProtocolParameters (out , gson , des , req );
118
+ streamGeckoDriver013Parameters (out , gson , des );
119
+ streamW3CProtocolParameters (out , gson , des );
125
120
out .endObject ();
126
121
127
122
out .endObject ();
@@ -146,27 +141,22 @@ public Result createSession(HttpClient client, Command command)
146
141
throw new SessionNotCreatedException (
147
142
String .format (
148
143
"Unable to create new remote session. " +
149
- "desired capabilities = %s, required capabilities = %s" ,
150
- desired ,
151
- required ));
144
+ "desired capabilities = %s" ,
145
+ desired ));
152
146
}
153
147
154
148
private void streamJsonWireProtocolParameters (
155
149
JsonWriter out ,
156
150
Gson gson ,
157
- JsonObject des ,
158
- JsonObject req ) throws IOException {
151
+ JsonObject des ) throws IOException {
159
152
out .name ("desiredCapabilities" );
160
153
gson .toJson (des , out );
161
- out .name ("requiredCapabilities" );
162
- gson .toJson (req , out );
163
154
}
164
155
165
156
private void streamW3CProtocolParameters (
166
157
JsonWriter out ,
167
158
Gson gson ,
168
- JsonObject des ,
169
- JsonObject req ) throws IOException {
159
+ JsonObject des ) throws IOException {
170
160
// Technically we should be building up a combination of "alwaysMatch" and "firstMatch" options.
171
161
// We're going to do a little processing to figure out what we might be able to do, and assume
172
162
// that people don't really understand the difference between required and desired (which is
@@ -187,35 +177,27 @@ private void streamW3CProtocolParameters(
187
177
// We can't use the constants defined in the classes because it would introduce circular
188
178
// dependencies between the remote library and the implementations. Yay!
189
179
190
- Map <String , ?> chrome = Stream .of (des , req )
191
- .map (JsonObject ::entrySet )
192
- .flatMap (Collection ::stream )
180
+ Map <String , ?> chrome = des .entrySet ().stream ()
193
181
.filter (entry ->
194
182
("browserName" .equals (entry .getKey ()) && CHROME .equals (entry .getValue ().getAsString ())) ||
195
183
"chromeOptions" .equals (entry .getKey ()))
196
184
.distinct ()
197
185
.collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue , (left , right ) -> right ));
198
186
199
- Map <String , ?> edge = Stream .of (des , req )
200
- .map (JsonObject ::entrySet )
201
- .flatMap (Collection ::stream )
187
+ Map <String , ?> edge = des .entrySet ().stream ()
202
188
.filter (entry -> ("browserName" .equals (entry .getKey ()) && EDGE .equals (entry .getValue ().getAsString ())))
203
189
.distinct ()
204
190
.collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue , (left , right ) -> right ));
205
191
206
- Map <String , ?> firefox = Stream .of (des , req )
207
- .map (JsonObject ::entrySet )
208
- .flatMap (Collection ::stream )
192
+ Map <String , ?> firefox = des .entrySet ().stream ()
209
193
.filter (entry ->
210
194
("browserName" .equals (entry .getKey ()) && FIREFOX .equals (entry .getValue ().getAsString ())) ||
211
195
entry .getKey ().startsWith ("firefox_" ) ||
212
196
entry .getKey ().startsWith ("moz:" ))
213
197
.distinct ()
214
198
.collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue , (left , right ) -> right ));
215
199
216
- Map <String , ?> ie = Stream .of (req , des )
217
- .map (JsonObject ::entrySet )
218
- .flatMap (Collection ::stream )
200
+ Map <String , ?> ie = des .entrySet ().stream ()
219
201
.filter (entry ->
220
202
("browserName" .equals (entry .getKey ()) && IE .equals (entry .getValue ().getAsString ())) ||
221
203
"browserAttachTimeout" .equals (entry .getKey ()) ||
@@ -234,19 +216,15 @@ private void streamW3CProtocolParameters(
234
216
.distinct ()
235
217
.collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue , (left , right ) -> right ));
236
218
237
- Map <String , ?> opera = Stream .of (des , req )
238
- .map (JsonObject ::entrySet )
239
- .flatMap (Collection ::stream )
219
+ Map <String , ?> opera = des .entrySet ().stream ()
240
220
.filter (entry ->
241
221
("browserName" .equals (entry .getKey ()) && OPERA_BLINK .equals (entry .getValue ().getAsString ())) ||
242
222
("browserName" .equals (entry .getKey ()) && OPERA .equals (entry .getValue ().getAsString ())) ||
243
223
"operaOptions" .equals (entry .getKey ()))
244
224
.distinct ()
245
225
.collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue , (left , right ) -> right ));
246
226
247
- Map <String , ?> safari = Stream .of (des , req )
248
- .map (JsonObject ::entrySet )
249
- .flatMap (Collection ::stream )
227
+ Map <String , ?> safari = des .entrySet ().stream ()
250
228
.filter (entry ->
251
229
("browserName" .equals (entry .getKey ()) && SAFARI .equals (entry .getValue ().getAsString ())) ||
252
230
"safari.options" .equals (entry .getKey ()))
@@ -259,7 +237,7 @@ private void streamW3CProtocolParameters(
259
237
.distinct ()
260
238
.collect (ImmutableSet .toImmutableSet ());
261
239
262
- JsonObject alwaysMatch = Stream .of (des , req )
240
+ JsonObject alwaysMatch = Stream .of (des )
263
241
.map (JsonObject ::entrySet )
264
242
.flatMap (Collection ::stream )
265
243
.filter (entry -> !excludedKeys .contains (entry .getKey ()))
@@ -363,12 +341,9 @@ public Optional<Result> createSession(HttpClient client, InputStream newSessionB
363
341
private void streamGeckoDriver013Parameters (
364
342
JsonWriter out ,
365
343
Gson gson ,
366
- JsonObject des ,
367
- JsonObject req ) throws IOException {
344
+ JsonObject des ) throws IOException {
368
345
out .name ("desiredCapabilities" );
369
346
gson .toJson (des , out );
370
- out .name ("requiredCapabilities" );
371
- gson .toJson (req , out );
372
347
}
373
348
374
349
public static class Result {
0 commit comments