Skip to content

Commit

Permalink
Merge pull request #249 from testcontainers/override-selenium-image
Browse files Browse the repository at this point in the history
Allow docker image used for selenium to be specified
  • Loading branch information
rnorth authored Jan 16, 2017
2 parents c740e17 + 8efdaa8 commit 398c6b6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <p>
Expand All @@ -36,15 +40,16 @@ public class BrowserWebDriverContainer<SELF extends BrowserWebDriverContainer<SE

@Nullable
private DesiredCapabilities desiredCapabilities;
private boolean customImageNameIsSet = false;

@Nullable
private RemoteWebDriver driver;

private VncRecordingMode recordingMode = VncRecordingMode.RECORD_FAILING;
private File vncRecordingDirectory = new File("/tmp");

private final Collection<VncRecordingSidekickContainer> currentVncRecordings = new ArrayList<>();

private static final Logger LOGGER = LoggerFactory.getLogger(BrowserWebDriverContainer.class);

private static final SimpleDateFormat filenameDateFormat = new SimpleDateFormat("YYYYMMdd-HHmmss");

/**
Expand All @@ -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();
}
Expand All @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 398c6b6

Please sign in to comment.