Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow docker image used for selenium to be specified #249

Merged
merged 2 commits into from
Jan 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

сan't we just inherit this tests from BaseWebDriverContainerTest?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @Test methods? We've not done this yet in the other subclasses. I guess this would require making the container field be a protected member of the parent class and initialize it in the subclass constructors. Or is there a simpler way?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can make the parent class abstract with abstract protected BrowserWebDriverContainer getContainer() method. We were using something like that in Zipkin's tests:
https://github.com/openzipkin/zipkin/blob/master/zipkin-storage/mysql/src/test/java/zipkin/storage/mysql/MySQLTest.java

public void simpleTest() throws IOException {
doSimpleWebdriverTest(firefox);
}

@Test
public void simpleExploreTest() throws IOException {
doSimpleExplore(firefox);
}
}