Skip to content

Commit 55d735b

Browse files
authored
[java] WebSocket NoVNC session against the grid URL contains trailing slash (#13353)
Signed-off-by: Viet Nguyen Duc <[email protected]>
1 parent 6b9dfec commit 55d735b

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

java/src/org/openqa/selenium/grid/node/local/LocalNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ private Session createExternalSession(
838838
private URI rewrite(String path) {
839839
try {
840840
String scheme = "https".equals(gridUri.getScheme()) ? "wss" : "ws";
841-
if (gridUri.getPath() != null && !gridUri.getPath().isEmpty()) {
841+
if (gridUri.getPath() != null && !gridUri.getPath().equals("/")) {
842842
path = gridUri.getPath() + path;
843843
}
844844
return new URI(

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,41 @@ void seVncCdpUrlCapabilityWhenGridUrlWithSubPath() throws URISyntaxException {
315315
assertThat(seCdp.toString().contains(gridUrl.replace("http", "ws"))).isTrue();
316316
}
317317

318+
@Test
319+
void seVncCdpUrlCapabilityWhenGridUrlWithTrailingSlash() throws URISyntaxException {
320+
Tracer tracer = DefaultTestTracer.createTracer();
321+
EventBus bus = new GuavaEventBus();
322+
URI uri = new URI("https://my.domain.com/");
323+
Capabilities stereotype =
324+
new ImmutableCapabilities(
325+
"se:vncLocalAddress", "ws://localhost:7900",
326+
"se:cdp", "ws://localhost:9222/devtools/browser/1a2b3c4d5e6f");
327+
328+
LocalNode.Builder builder =
329+
LocalNode.builder(tracer, bus, uri, uri, registrationSecret)
330+
.enableCdp(true)
331+
.add(
332+
stereotype,
333+
new TestSessionFactory(
334+
(id, caps) -> new Session(id, uri, stereotype, caps, Instant.now())));
335+
LocalNode localNode = builder.build();
336+
337+
Either<WebDriverException, CreateSessionResponse> response =
338+
localNode.newSession(
339+
new CreateSessionRequest(ImmutableSet.of(W3C), stereotype, ImmutableMap.of()));
340+
assertThat(response.isRight()).isTrue();
341+
342+
CreateSessionResponse sessionResponse = response.right();
343+
Capabilities capabilities = sessionResponse.getSession().getCapabilities();
344+
Object seVnc = capabilities.getCapability("se:vnc");
345+
assertThat(seVnc).isNotNull();
346+
assertThat(seVnc.toString().contains("wss://my.domain.com/session")).isTrue();
347+
348+
Object seCdp = capabilities.getCapability("se:cdp");
349+
assertThat(seCdp).isNotNull();
350+
assertThat(seCdp.toString().contains("wss://my.domain.com/session")).isTrue();
351+
}
352+
318353
@Test
319354
void cdpIsDisabledAndResponseCapsShowThat() throws URISyntaxException {
320355
Tracer tracer = DefaultTestTracer.createTracer();

0 commit comments

Comments
 (0)