Skip to content

Commit

Permalink
[java] Add "se" prefixed capabilities to session response (SeleniumHQ…
Browse files Browse the repository at this point in the history
…#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]>
  • Loading branch information
pujagani and diemol authored Aug 9, 2024
1 parent 00a3f4c commit 13be88d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sess

caps = readDevToolsEndpointAndVersion(caps);
caps = readVncEndpoint(capabilities, caps);
caps = readPrefixedCaps(capabilities, caps);

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

private Capabilities readPrefixedCaps(Capabilities requestedCaps, Capabilities returnedCaps) {

PersistentCapabilities returnPrefixedCaps = new PersistentCapabilities(returnedCaps);

Map<String, Object> requestedCapsMap = requestedCaps.asMap();
Map<String, Object> returnedCapsMap = returnedCaps.asMap();

requestedCapsMap.forEach(
(k, v) -> {
if (k.startsWith("se:") && !returnedCapsMap.containsKey(k)) {
returnPrefixedCaps.setCapability(k, v);
}
});

return returnPrefixedCaps;
}

// We remove a capability before sending the caps to the driver because some drivers will
// reject session requests when they cannot parse the specific capabilities (like platform or
// browser version).
Expand Down
29 changes: 29 additions & 0 deletions java/test/org/openqa/selenium/grid/node/local/LocalNodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,35 @@ void seVncCdpUrlCapabilityWhenGridUrlWithTrailingSlash() throws URISyntaxExcepti
assertThat(seCdp.toString().contains("wss://my.domain.com/session")).isTrue();
}

@Test
void responseCapsShowContainerName() throws URISyntaxException {
Tracer tracer = DefaultTestTracer.createTracer();
EventBus bus = new GuavaEventBus();

String gridUrl = "http://localhost:7890/subPath";
URI uri = new URI(gridUrl);
Capabilities stereotype = new ImmutableCapabilities("se:containerName", "container-1");

LocalNode.Builder builder =
LocalNode.builder(tracer, bus, uri, uri, registrationSecret)
.add(
stereotype,
new TestSessionFactory(
(id, caps) -> new Session(id, uri, stereotype, caps, Instant.now())));
LocalNode localNode = builder.build();

Either<WebDriverException, CreateSessionResponse> response =
localNode.newSession(
new CreateSessionRequest(ImmutableSet.of(W3C), stereotype, ImmutableMap.of()));
assertThat(response.isRight()).isTrue();

CreateSessionResponse sessionResponse = response.right();
Capabilities capabilities = sessionResponse.getSession().getCapabilities();
Object seContainerName = capabilities.getCapability("se:containerName");
assertThat(seContainerName).isNotNull();
assertThat(seContainerName).isEqualTo("container-1");
}

@Test
void cdpIsDisabledAndResponseCapsShowThat() throws URISyntaxException {
Tracer tracer = DefaultTestTracer.createTracer();
Expand Down

0 comments on commit 13be88d

Please sign in to comment.