diff --git a/modules/selenium/src/main/java/org/testcontainers/containers/BrowserWebDriverContainer.java b/modules/selenium/src/main/java/org/testcontainers/containers/BrowserWebDriverContainer.java index 76feff2840f..7809de4f42a 100644 --- a/modules/selenium/src/main/java/org/testcontainers/containers/BrowserWebDriverContainer.java +++ b/modules/selenium/src/main/java/org/testcontainers/containers/BrowserWebDriverContainer.java @@ -131,7 +131,11 @@ protected void configure() { addExposedPorts(SELENIUM_PORT, VNC_PORT); addEnv("TZ", timeZone); - addEnv("no_proxy", "localhost"); + + if (!getEnvMap().containsKey("no_proxy")) { + addEnv("no_proxy", "localhost"); + } + setCommand("/opt/bin/entry_point.sh"); /* diff --git a/modules/selenium/src/test/java/org/testcontainers/junit/BrowserWebDriverContainerTest.java b/modules/selenium/src/test/java/org/testcontainers/junit/BrowserWebDriverContainerTest.java new file mode 100644 index 00000000000..16ce8926f3c --- /dev/null +++ b/modules/selenium/src/test/java/org/testcontainers/junit/BrowserWebDriverContainerTest.java @@ -0,0 +1,34 @@ +package org.testcontainers.junit; + +import org.junit.Rule; +import org.junit.Test; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.testcontainers.containers.BrowserWebDriverContainer; + +import static org.rnorth.visibleassertions.VisibleAssertions.assertEquals; + +public class BrowserWebDriverContainerTest { + + private static final String NO_PROXY_VALUE = "localhost,.noproxy-domain.com"; + + @Rule + public BrowserWebDriverContainer chromeWithNoProxySet = (BrowserWebDriverContainer) new BrowserWebDriverContainer() + .withDesiredCapabilities(DesiredCapabilities.chrome()) + .withEnv("no_proxy", NO_PROXY_VALUE); + + @Rule + public BrowserWebDriverContainer chromeWithoutNoProxySet = new BrowserWebDriverContainer() + .withDesiredCapabilities(DesiredCapabilities.chrome()); + + @Test + public void honorPresetNoProxyEnvironment() { + Object no_proxy = chromeWithNoProxySet.getEnvMap().get("no_proxy"); + assertEquals("no_proxy should be preserved by the container rule", NO_PROXY_VALUE, no_proxy); + } + + @Test + public void provideDefaultNoProxyEnvironmentIfNotSet() { + Object no_proxy = chromeWithoutNoProxySet.getEnvMap().get("no_proxy"); + assertEquals("no_proxy should be set to default if not already present", "localhost", no_proxy); + } +}