diff --git a/java/src/org/openqa/selenium/grid/node/config/NodeFlags.java b/java/src/org/openqa/selenium/grid/node/config/NodeFlags.java index 3d49df5f713b3..800a0798a4e17 100644 --- a/java/src/org/openqa/selenium/grid/node/config/NodeFlags.java +++ b/java/src/org/openqa/selenium/grid/node/config/NodeFlags.java @@ -30,7 +30,7 @@ import static org.openqa.selenium.grid.node.config.NodeOptions.DEFAULT_REGISTER_PERIOD; import static org.openqa.selenium.grid.node.config.NodeOptions.DEFAULT_SESSION_TIMEOUT; import static org.openqa.selenium.grid.node.config.NodeOptions.DEFAULT_USE_SELENIUM_MANAGER; -import static org.openqa.selenium.grid.node.config.NodeOptions.DEFAULT_VNC_ENV_VAR; +import static org.openqa.selenium.grid.node.config.NodeOptions.DEFAULT_VNC_ENV_VARS; import static org.openqa.selenium.grid.node.config.NodeOptions.NODE_SECTION; import static org.openqa.selenium.grid.node.config.NodeOptions.OVERRIDE_MAX_SESSIONS; @@ -202,8 +202,11 @@ public class NodeFlags implements HasRoles { description = "Environment variable to check in order to determine if a vnc stream is " + "available or not.") - @ConfigValue(section = NODE_SECTION, name = "vnc-env-var", example = "SE_START_XVFB") - public String vncEnvVar = DEFAULT_VNC_ENV_VAR; + @ConfigValue( + section = NODE_SECTION, + name = "vnc-env-var", + example = "[\"SE_START_XVFB\", \"SE_START_VNC\", \"SE_START_NO_VNC\"]") + public List vncEnvVar = DEFAULT_VNC_ENV_VARS; @Parameter( names = "--no-vnc-port", diff --git a/java/src/org/openqa/selenium/grid/node/config/NodeOptions.java b/java/src/org/openqa/selenium/grid/node/config/NodeOptions.java index 8f7ea2dd68aaa..7317f6e7c8870 100644 --- a/java/src/org/openqa/selenium/grid/node/config/NodeOptions.java +++ b/java/src/org/openqa/selenium/grid/node/config/NodeOptions.java @@ -31,6 +31,7 @@ import java.net.URISyntaxException; import java.time.Duration; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Comparator; import java.util.HashMap; @@ -78,7 +79,8 @@ public class NodeOptions { static final boolean DEFAULT_DETECT_DRIVERS = true; static final boolean DEFAULT_USE_SELENIUM_MANAGER = false; static final boolean OVERRIDE_MAX_SESSIONS = false; - static final String DEFAULT_VNC_ENV_VAR = "SE_START_XVFB"; + static final List DEFAULT_VNC_ENV_VARS = + Arrays.asList("SE_START_XVFB", "SE_START_VNC", "SE_START_NO_VNC"); static final int DEFAULT_NO_VNC_PORT = 7900; static final int DEFAULT_REGISTER_CYCLE = 10; static final int DEFAULT_REGISTER_PERIOD = 120; @@ -286,9 +288,16 @@ public int getDrainAfterSessionCount() { @VisibleForTesting boolean isVncEnabled() { - String vncEnvVar = config.get(NODE_SECTION, "vnc-env-var").orElse(DEFAULT_VNC_ENV_VAR); + List vncEnvVars = DEFAULT_VNC_ENV_VARS; + if (config.getAll(NODE_SECTION, "vnc-env-var").isPresent()) { + vncEnvVars = config.getAll(NODE_SECTION, "vnc-env-var").get(); + } if (!vncEnabledValueSet.getAndSet(true)) { - vncEnabled.set(Boolean.parseBoolean(System.getenv(vncEnvVar))); + boolean allEnabled = + vncEnvVars.stream() + .allMatch( + env -> "true".equalsIgnoreCase(System.getProperty(env, System.getenv(env)))); + vncEnabled.set(allEnabled); } return vncEnabled.get(); } 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 43d413cdab362..69f1ba30a9ee9 100644 --- a/java/test/org/openqa/selenium/grid/node/config/NodeOptionsTest.java +++ b/java/test/org/openqa/selenium/grid/node/config/NodeOptionsTest.java @@ -719,6 +719,50 @@ void settingSlotMatcherAvailable() { assertThat(nodeOptions.getSlotMatcher()).isExactlyInstanceOf(YesSlotMatcher.class); } + @Test + void testIsVncEnabledAcceptListEnvVarsAndReturnTrue() { + System.setProperty("SE_START_XVFB", "true"); + System.setProperty("SE_START_VNC", "true"); + System.setProperty("SE_START_NO_VNC", "true"); + String[] rawConfig = + new String[] { + "[node]", "vnc-env-var = [\"SE_START_XVFB\", \"SE_START_VNC\", \"SE_START_NO_VNC\"]", + }; + Config config = new TomlConfig(new StringReader(String.join("\n", rawConfig))); + NodeOptions nodeOptionsEnabled = new NodeOptions(config); + assertThat(config.getAll("node", "vnc-env-var").get()) + .containsExactly("SE_START_XVFB", "SE_START_VNC", "SE_START_NO_VNC"); + assertThat(nodeOptionsEnabled.isVncEnabled()).isTrue(); + } + + @Test + void testIsVncEnabledAcceptListEnvVarsAndReturnFalse() { + System.setProperty("SE_START_XVFB", "true"); + System.setProperty("SE_START_VNC", "false"); + String[] rawConfig = + new String[] { + "[node]", "vnc-env-var = [\"SE_START_XVFB\", \"SE_START_VNC\", \"SE_START_NO_VNC\"]", + }; + Config config = new TomlConfig(new StringReader(String.join("\n", rawConfig))); + NodeOptions nodeOptionsEnabled = new NodeOptions(config); + assertThat(config.getAll("node", "vnc-env-var").get()) + .containsExactly("SE_START_XVFB", "SE_START_VNC", "SE_START_NO_VNC"); + assertThat(nodeOptionsEnabled.isVncEnabled()).isFalse(); + } + + @Test + void testIsVncEnabledAcceptSingleEnvVar() { + System.setProperty("SE_START_XVFB", "false"); + String[] rawConfig = + new String[] { + "[node]", "vnc-env-var = \"SE_START_XVFB\"", + }; + Config config = new TomlConfig(new StringReader(String.join("\n", rawConfig))); + NodeOptions nodeOptionsEnabled = new NodeOptions(config); + assertThat(config.getAll("node", "vnc-env-var").get()).containsExactly("SE_START_XVFB"); + assertThat(nodeOptionsEnabled.isVncEnabled()).isFalse(); + } + private Condition> supporting(String name) { return new Condition<>( caps -> caps.stream().anyMatch(cap -> name.equals(cap.getBrowserName())),