Skip to content

Commit b59a9fb

Browse files
authored
[java] bug(#12791) Grid vnc session is not using the --sub-path argument (#13219)
Signed-off-by: Viet Nguyen Duc <[email protected]>
1 parent 252b462 commit b59a9fb

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,9 @@ 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()) {
842+
path = gridUri.getPath() + path;
843+
}
841844
return new URI(
842845
scheme, gridUri.getUserInfo(), gridUri.getHost(), gridUri.getPort(), path, null, null);
843846
} catch (URISyntaxException e) {

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,42 @@ void nodeDrainsAfterSessionCountIsReached() throws URISyntaxException {
279279
assertThat(localNode.isDraining()).isTrue();
280280
}
281281

282+
@Test
283+
void seVncCdpUrlCapabilityWhenGridUrlWithSubPath() throws URISyntaxException {
284+
Tracer tracer = DefaultTestTracer.createTracer();
285+
EventBus bus = new GuavaEventBus();
286+
String gridUrl = "http://localhost:7890/subPath";
287+
URI uri = new URI(gridUrl);
288+
Capabilities stereotype =
289+
new ImmutableCapabilities(
290+
"se:vncLocalAddress", "ws://localhost:7900",
291+
"se:cdp", "ws://localhost:9222/devtools/browser/1a2b3c4d5e6f");
292+
293+
LocalNode.Builder builder =
294+
LocalNode.builder(tracer, bus, uri, uri, registrationSecret)
295+
.enableCdp(true)
296+
.add(
297+
stereotype,
298+
new TestSessionFactory(
299+
(id, caps) -> new Session(id, uri, stereotype, caps, Instant.now())));
300+
LocalNode localNode = builder.build();
301+
302+
Either<WebDriverException, CreateSessionResponse> response =
303+
localNode.newSession(
304+
new CreateSessionRequest(ImmutableSet.of(W3C), stereotype, ImmutableMap.of()));
305+
assertThat(response.isRight()).isTrue();
306+
307+
CreateSessionResponse sessionResponse = response.right();
308+
Capabilities capabilities = sessionResponse.getSession().getCapabilities();
309+
Object seVnc = capabilities.getCapability("se:vnc");
310+
assertThat(seVnc).isNotNull();
311+
assertThat(seVnc.toString().contains(gridUrl.replace("http", "ws"))).isTrue();
312+
313+
Object seCdp = capabilities.getCapability("se:cdp");
314+
assertThat(seCdp).isNotNull();
315+
assertThat(seCdp.toString().contains(gridUrl.replace("http", "ws"))).isTrue();
316+
}
317+
282318
@Test
283319
void cdpIsDisabledAndResponseCapsShowThat() throws URISyntaxException {
284320
Tracer tracer = DefaultTestTracer.createTracer();

0 commit comments

Comments
 (0)