Skip to content

Commit 458c350

Browse files
authored
[grid] Fix VNC caps not propagated for sessions without browserName (#17235)
Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
1 parent b1a7b8d commit 458c350

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

‎java/src/org/openqa/selenium/grid/node/config/SessionCapabilitiesMutator.java‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@ public SessionCapabilitiesMutator(Capabilities slotStereotype) {
4646

4747
@Override
4848
public Capabilities apply(Capabilities capabilities) {
49-
if (!Objects.equals(slotStereotype.getBrowserName(), capabilities.getBrowserName())) {
50-
return capabilities;
51-
}
52-
49+
// Always propagate VNC capabilities from the stereotype, regardless of whether the session
50+
// request included a browserName. Requests without browserName (e.g. proxy-only caps) are
51+
// still routed to a slot that has VNC enabled, so the VNC address must be present.
5352
Object vncEnabled = slotStereotype.getCapability(SE_VNC_ENABLED);
5453
if (vncEnabled != null) {
5554
Object vncPort = slotStereotype.getCapability(SE_NO_VNC_PORT);
@@ -59,6 +58,10 @@ public Capabilities apply(Capabilities capabilities) {
5958
.setCapability(SE_NO_VNC_PORT, Require.nonNull(SE_NO_VNC_PORT, vncPort));
6059
}
6160

61+
if (!Objects.equals(slotStereotype.getBrowserName(), capabilities.getBrowserName())) {
62+
return capabilities;
63+
}
64+
6265
String browserName = capabilities.getBrowserName().toLowerCase(Locale.ENGLISH);
6366

6467
if ("internet explorer".equalsIgnoreCase(browserName)) {

‎java/test/org/openqa/selenium/grid/node/config/SessionCapabilitiesMutatorTest.java‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,26 @@ void shouldMergeTopLevelStereotypeAndCaps() {
343343
assertThat(modifiedCapabilities.get("pageLoadStrategy")).isEqualTo("normal");
344344
}
345345

346+
@Test
347+
void shouldPropagateVncCapsWhenRequestHasNoBrowserName() {
348+
// Requests without browserName (e.g. proxy-only caps) are still routed to a VNC-enabled slot;
349+
// the VNC address must be present in the merged capabilities.
350+
Capabilities stereotype =
351+
new ImmutableCapabilities(
352+
"browserName", "chrome", "se:vncEnabled", true, "se:noVncPort", 7900);
353+
354+
SessionCapabilitiesMutator sessionCapabilitiesMutator =
355+
new SessionCapabilitiesMutator(stereotype);
356+
357+
Capabilities capabilities = new ImmutableCapabilities("proxy", Map.of("proxyType", "direct"));
358+
359+
Map<String, Object> modifiedCapabilities =
360+
sessionCapabilitiesMutator.apply(capabilities).asMap();
361+
362+
assertThat(modifiedCapabilities.get("se:vncEnabled")).isEqualTo(true);
363+
assertThat(modifiedCapabilities.get("se:noVncPort")).isEqualTo(7900);
364+
}
365+
346366
@Test
347367
void shouldAllowUnknownBrowserNames() {
348368
Capabilities stereotype = new ImmutableCapabilities("browserName", "safari");

0 commit comments

Comments
 (0)