Skip to content

Commit 13be88d

Browse files
pujaganidiemol
andauthored
[java] Add "se" prefixed capabilities to session response (#14323)
* [java] Add "se:containerName" to session response * Ensure all prefixed caps in request are added in response --------- Co-authored-by: Diego Molina <[email protected]>
1 parent 00a3f4c commit 13be88d

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

java/src/org/openqa/selenium/grid/node/config/DriverServiceSessionFactory.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sess
187187

188188
caps = readDevToolsEndpointAndVersion(caps);
189189
caps = readVncEndpoint(capabilities, caps);
190+
caps = readPrefixedCaps(capabilities, caps);
190191

191192
span.addEvent("Driver service created session", attributeMap);
192193
final HttpClient fClient = client;
@@ -300,6 +301,23 @@ private Capabilities readVncEndpoint(Capabilities requestedCaps, Capabilities re
300301
return returnedCaps;
301302
}
302303

304+
private Capabilities readPrefixedCaps(Capabilities requestedCaps, Capabilities returnedCaps) {
305+
306+
PersistentCapabilities returnPrefixedCaps = new PersistentCapabilities(returnedCaps);
307+
308+
Map<String, Object> requestedCapsMap = requestedCaps.asMap();
309+
Map<String, Object> returnedCapsMap = returnedCaps.asMap();
310+
311+
requestedCapsMap.forEach(
312+
(k, v) -> {
313+
if (k.startsWith("se:") && !returnedCapsMap.containsKey(k)) {
314+
returnPrefixedCaps.setCapability(k, v);
315+
}
316+
});
317+
318+
return returnPrefixedCaps;
319+
}
320+
303321
// We remove a capability before sending the caps to the driver because some drivers will
304322
// reject session requests when they cannot parse the specific capabilities (like platform or
305323
// browser version).

java/test/org/openqa/selenium/grid/node/local/LocalNodeTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,35 @@ void seVncCdpUrlCapabilityWhenGridUrlWithTrailingSlash() throws URISyntaxExcepti
350350
assertThat(seCdp.toString().contains("wss://my.domain.com/session")).isTrue();
351351
}
352352

353+
@Test
354+
void responseCapsShowContainerName() throws URISyntaxException {
355+
Tracer tracer = DefaultTestTracer.createTracer();
356+
EventBus bus = new GuavaEventBus();
357+
358+
String gridUrl = "http://localhost:7890/subPath";
359+
URI uri = new URI(gridUrl);
360+
Capabilities stereotype = new ImmutableCapabilities("se:containerName", "container-1");
361+
362+
LocalNode.Builder builder =
363+
LocalNode.builder(tracer, bus, uri, uri, registrationSecret)
364+
.add(
365+
stereotype,
366+
new TestSessionFactory(
367+
(id, caps) -> new Session(id, uri, stereotype, caps, Instant.now())));
368+
LocalNode localNode = builder.build();
369+
370+
Either<WebDriverException, CreateSessionResponse> response =
371+
localNode.newSession(
372+
new CreateSessionRequest(ImmutableSet.of(W3C), stereotype, ImmutableMap.of()));
373+
assertThat(response.isRight()).isTrue();
374+
375+
CreateSessionResponse sessionResponse = response.right();
376+
Capabilities capabilities = sessionResponse.getSession().getCapabilities();
377+
Object seContainerName = capabilities.getCapability("se:containerName");
378+
assertThat(seContainerName).isNotNull();
379+
assertThat(seContainerName).isEqualTo("container-1");
380+
}
381+
353382
@Test
354383
void cdpIsDisabledAndResponseCapsShowThat() throws URISyntaxException {
355384
Tracer tracer = DefaultTestTracer.createTracer();

0 commit comments

Comments
 (0)