From 56c8fea38be891e12d9dda01a269c73ea80c6ca4 Mon Sep 17 00:00:00 2001 From: Viet Nguyen Duc Date: Fri, 22 Dec 2023 11:08:20 +0530 Subject: [PATCH] [java] WebSocket NoVNC session against the grid URL contains trailing slash Signed-off-by: Viet Nguyen Duc --- .../selenium/grid/node/local/LocalNode.java | 2 +- .../grid/node/local/LocalNodeTest.java | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/java/src/org/openqa/selenium/grid/node/local/LocalNode.java b/java/src/org/openqa/selenium/grid/node/local/LocalNode.java index 9f9e2a3ab6ad91..1c7b2f31b156c5 100644 --- a/java/src/org/openqa/selenium/grid/node/local/LocalNode.java +++ b/java/src/org/openqa/selenium/grid/node/local/LocalNode.java @@ -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( diff --git a/java/test/org/openqa/selenium/grid/node/local/LocalNodeTest.java b/java/test/org/openqa/selenium/grid/node/local/LocalNodeTest.java index 964da99fc1afbf..e27e95d25c2fff 100644 --- a/java/test/org/openqa/selenium/grid/node/local/LocalNodeTest.java +++ b/java/test/org/openqa/selenium/grid/node/local/LocalNodeTest.java @@ -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 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();