From 0a8db1776848ed19f70f0a6cf9875ee2e5555f1b Mon Sep 17 00:00:00 2001 From: Viet Nguyen Duc Date: Wed, 29 Nov 2023 12:45:14 +0530 Subject: [PATCH] [java] WebSocket connection for vnc session is not using the --sub-path argument Signed-off-by: Viet Nguyen Duc --- .../selenium/grid/node/local/LocalNode.java | 3 ++ .../grid/node/config/NodeOptionsTest.java | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+) 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 4c11c15209ca3..9f9e2a3ab6ad9 100644 --- a/java/src/org/openqa/selenium/grid/node/local/LocalNode.java +++ b/java/src/org/openqa/selenium/grid/node/local/LocalNode.java @@ -838,6 +838,9 @@ private Session createExternalSession( private URI rewrite(String path) { try { String scheme = "https".equals(gridUri.getScheme()) ? "wss" : "ws"; + if (gridUri.getPath() != null && !gridUri.getPath().isEmpty()) { + path = gridUri.getPath() + path; + } return new URI( scheme, gridUri.getUserInfo(), gridUri.getHost(), gridUri.getPort(), path, null, null); } catch (URISyntaxException e) { diff --git a/java/test/org/openqa/selenium/grid/node/config/NodeOptionsTest.java b/java/test/org/openqa/selenium/grid/node/config/NodeOptionsTest.java index 6eff850a9db54..cdec80a3c41d5 100644 --- a/java/test/org/openqa/selenium/grid/node/config/NodeOptionsTest.java +++ b/java/test/org/openqa/selenium/grid/node/config/NodeOptionsTest.java @@ -235,6 +235,36 @@ void platformNameIsAddedByDefault() { .hasSize(reported.size()); } + @Test + void seVncUrlSeCdpUrlCapabilityWhenGridUrlWithSubPath() { + String gridUrl = "http://localhost:4444/subPath"; + Config config = new MapConfig(singletonMap("node", singletonMap("grid-url", gridUrl))); + + List reported = new ArrayList<>(); + NodeOptions nodeOptions = new NodeOptions(config); + NodeOptions nodeOptionsSpy = Mockito.spy(nodeOptions); + Mockito.doReturn(true).when(nodeOptionsSpy).isVncEnabled(); + nodeOptionsSpy.getSessionFactories( + caps -> { + reported.add(caps); + return Collections.singleton(HelperFactory.create(config, caps)); + }); + + assertThat(reported) + .filteredOn( + capabilities -> + capabilities.getCapability("se:vnc") != null + && String.valueOf(capabilities.getCapability("se:vnc")).contains(gridUrl)) + .hasSize(reported.size()); + + assertThat(reported) + .filteredOn( + capabilities -> + capabilities.getCapability("se:cdp") != null + && String.valueOf(capabilities.getCapability("se:cdp")).contains(gridUrl)) + .hasSize(reported.size()); + } + @Test void vncEnabledCapabilityIsAddedWhenEnvVarIsTrue() { Config config = new MapConfig(singletonMap("node", singletonMap("detect-drivers", "false")));