Skip to content

Commit ed5fba8

Browse files
shs96cTikhomirovSergey
authored andcommitted
Ensure that we forward metadata in the new session payload
1 parent f860f33 commit ed5fba8

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

src/main/java/org/openqa/selenium/remote/NewSessionPayload.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,7 @@ public void writeTo(Appendable appendable) throws IOException {
219219

220220
Map<String, Object> first = getOss();
221221
if (first == null) {
222-
//noinspection unchecked
223-
first = (Map<String, Object>) stream().findFirst()
222+
first = stream().findFirst()
224223
.orElse(new ImmutableCapabilities())
225224
.asMap();
226225
}
@@ -246,10 +245,36 @@ public void writeTo(Appendable appendable) throws IOException {
246245
json.endArray();
247246

248247
json.endObject(); // Close "capabilities" object
248+
249+
writeMetaData(json);
250+
249251
json.endObject();
250252
}
251253
}
252254

255+
private void writeMetaData(JsonOutput out) throws IOException {
256+
CharSource charSource = backingStore.asByteSource().asCharSource(UTF_8);
257+
try (Reader reader = charSource.openBufferedStream();
258+
JsonInput input = json.newInput(reader)) {
259+
input.beginObject();
260+
while (input.hasNext()) {
261+
String name = input.nextName();
262+
switch (name) {
263+
case "capabilities":
264+
case "desiredCapabilities":
265+
case "requiredCapabilities":
266+
input.skipValue();
267+
break;
268+
269+
default:
270+
out.name(name);
271+
out.write(input.<Object>read(Object.class), Object.class);
272+
break;
273+
}
274+
}
275+
}
276+
}
277+
253278
private void streamW3CProtocolParameters(JsonOutput out, Map<String, Object> des) {
254279
// Technically we should be building up a combination of "alwaysMatch" and "firstMatch" options.
255280
// We're going to do a little processing to figure out what we might be able to do, and assume

0 commit comments

Comments
 (0)