Skip to content

[java] Add "se" prefixed capabilities to session response #14323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the issue is that setCapability returns a new PersistentCapabilities object and does not modify the current one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly. I fixed it via ef1b422.

}
});

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
Loading