Skip to content

Commit

Permalink
[java] WebSocket connection for vnc session is not using the --sub-pa…
Browse files Browse the repository at this point in the history
…th argument

Signed-off-by: Viet Nguyen Duc <[email protected]>
  • Loading branch information
VietND96 committed Nov 29, 2023
1 parent 36585d1 commit 0a8db17
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions java/src/org/openqa/selenium/grid/node/local/LocalNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Capabilities> 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")));
Expand Down

0 comments on commit 0a8db17

Please sign in to comment.