Skip to content

Commit

Permalink
[java] WebSocket NoVNC session against the grid URL contains trailing…
Browse files Browse the repository at this point in the history
… slash

Signed-off-by: Viet Nguyen Duc <[email protected]>
  • Loading branch information
VietND96 committed Dec 22, 2023
1 parent 6d18972 commit 56c8fea
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ private Session createExternalSession(
private URI rewrite(String path) {
try {
String scheme = "https".equals(gridUri.getScheme()) ? "wss" : "ws";
if (gridUri.getPath() != null && !gridUri.getPath().isEmpty()) {
if (gridUri.getPath() != null && !gridUri.getPath().equals("/")) {
path = gridUri.getPath() + path;
}
return new URI(
Expand Down
35 changes: 35 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 @@ -315,6 +315,41 @@ void seVncCdpUrlCapabilityWhenGridUrlWithSubPath() throws URISyntaxException {
assertThat(seCdp.toString().contains(gridUrl.replace("http", "ws"))).isTrue();
}

@Test
void seVncCdpUrlCapabilityWhenGridUrlWithTrailingSlash() throws URISyntaxException {
Tracer tracer = DefaultTestTracer.createTracer();
EventBus bus = new GuavaEventBus();
URI uri = new URI("https://my.domain.com/");
Capabilities stereotype =
new ImmutableCapabilities(
"se:vncLocalAddress", "ws://localhost:7900",
"se:cdp", "ws://localhost:9222/devtools/browser/1a2b3c4d5e6f");

LocalNode.Builder builder =
LocalNode.builder(tracer, bus, uri, uri, registrationSecret)
.enableCdp(true)
.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 seVnc = capabilities.getCapability("se:vnc");
assertThat(seVnc).isNotNull();
assertThat(seVnc.toString().contains("wss://my.domain.com/session")).isTrue();

Object seCdp = capabilities.getCapability("se:cdp");
assertThat(seCdp).isNotNull();
assertThat(seCdp.toString().contains("wss://my.domain.com/session")).isTrue();
}

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

0 comments on commit 56c8fea

Please sign in to comment.