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 4c7d6019c3b..1798ec41116 100644 --- a/modules/selenium/src/main/java/org/testcontainers/containers/BrowserWebDriverContainer.java +++ b/modules/selenium/src/main/java/org/testcontainers/containers/BrowserWebDriverContainer.java @@ -16,10 +16,14 @@ import java.net.MalformedURLException; import java.net.URL; import java.text.SimpleDateFormat; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import static com.google.common.base.Preconditions.checkState; + /** * A chrome/firefox/custom container based on SeleniumHQ's standalone container sets. *

@@ -36,15 +40,16 @@ public class BrowserWebDriverContainer currentVncRecordings = new ArrayList<>(); private static final Logger LOGGER = LoggerFactory.getLogger(BrowserWebDriverContainer.class); - private static final SimpleDateFormat filenameDateFormat = new SimpleDateFormat("YYYYMMdd-HHmmss"); /** @@ -53,9 +58,17 @@ public BrowserWebDriverContainer() { } + /** + * Constructor taking a specific webdriver container name and tag + * @param dockerImageName + */ + public BrowserWebDriverContainer(String dockerImageName) { + super.setDockerImageName(dockerImageName); + this.customImageNameIsSet = true; + } + public SELF withDesiredCapabilities(DesiredCapabilities desiredCapabilities) { - super.setDockerImageName(getImageForCapabilities(desiredCapabilities)); this.desiredCapabilities = desiredCapabilities; return self(); } @@ -67,6 +80,12 @@ protected Integer getLivenessCheckPort() { @Override protected void configure() { + + checkState(desiredCapabilities != null); + if (! customImageNameIsSet) { + super.setDockerImageName(getImageForCapabilities(desiredCapabilities)); + } + String timeZone = System.getProperty("user.timezone"); if (timeZone == null || timeZone.isEmpty()) { diff --git a/modules/selenium/src/test/java/org/testcontainers/junit/SpecificImageNameWebDriverContainerTest.java b/modules/selenium/src/test/java/org/testcontainers/junit/SpecificImageNameWebDriverContainerTest.java new file mode 100644 index 00000000000..1db034502ac --- /dev/null +++ b/modules/selenium/src/test/java/org/testcontainers/junit/SpecificImageNameWebDriverContainerTest.java @@ -0,0 +1,28 @@ +package org.testcontainers.junit; + +import org.junit.Rule; +import org.junit.Test; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.testcontainers.containers.BrowserWebDriverContainer; + +import java.io.IOException; + +/** + * + */ +public class SpecificImageNameWebDriverContainerTest extends BaseWebDriverContainerTest { + + @Rule + public BrowserWebDriverContainer firefox = new BrowserWebDriverContainer("selenium/standalone-firefox-debug:2.53.1-beryllium") + .withDesiredCapabilities(DesiredCapabilities.firefox()); + + @Test + public void simpleTest() throws IOException { + doSimpleWebdriverTest(firefox); + } + + @Test + public void simpleExploreTest() throws IOException { + doSimpleExplore(firefox); + } +}