Skip to content
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
7 changes: 7 additions & 0 deletions modules/selenium/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ dependencies {
provided 'org.seleniumhq.selenium:selenium-remote-driver:4.10.0'
provided 'org.seleniumhq.selenium:selenium-chrome-driver:4.10.0'

testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.11.0'

testImplementation 'org.junit.jupiter:junit-jupiter:5.13.4'
testImplementation platform('org.seleniumhq.selenium:selenium-bom:4.13.0')
testImplementation 'org.seleniumhq.selenium:selenium-firefox-driver'
testImplementation 'org.seleniumhq.selenium:selenium-edge-driver'
Expand All @@ -17,3 +20,7 @@ dependencies {

compileOnly 'org.jetbrains:annotations:26.0.2'
}

test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.testcontainers.junit;

import org.junit.ClassRule;
import org.openqa.selenium.By;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebElement;
Expand All @@ -15,15 +14,10 @@

import static org.assertj.core.api.Assertions.assertThat;

/**
*
*/
public class BaseWebDriverContainerTest {

@ClassRule
public static Network NETWORK = Network.newNetwork();

@ClassRule
public static GenericContainer<?> HELLO_WORLD = new GenericContainer<>(
DockerImageName.parse("testcontainers/helloworld:1.1.0")
)
Expand All @@ -32,6 +26,10 @@ public class BaseWebDriverContainerTest {
.withExposedPorts(8080, 8081)
.waitingFor(new HttpWaitStrategy());

static {
HELLO_WORLD.start();
}

protected static void doSimpleExplore(BrowserWebDriverContainer<?> rule, Capabilities capabilities) {
RemoteWebDriver driver = new RemoteWebDriver(rule.getSeleniumAddress(), capabilities);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import com.github.dockerjava.api.command.InspectContainerResponse;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.SystemUtils;
import org.junit.Assume;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.testcontainers.containers.BrowserWebDriverContainer;
Expand All @@ -14,15 +13,16 @@
import java.util.stream.Collectors;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assumptions.assumeThat;

public class BrowserWebDriverContainerTest {
class BrowserWebDriverContainerTest {

private static final String NO_PROXY_KEY = "no_proxy";

private static final String NO_PROXY_VALUE = "localhost,.noproxy-domain.com";

@Test
public void honorPresetNoProxyEnvironment() {
void honorPresetNoProxyEnvironment() {
try (
BrowserWebDriverContainer chromeWithNoProxySet = (BrowserWebDriverContainer) new BrowserWebDriverContainer()
.withCapabilities(new ChromeOptions())
Expand All @@ -36,7 +36,7 @@ public void honorPresetNoProxyEnvironment() {
}

@Test
public void provideDefaultNoProxyEnvironmentIfNotSet() {
void provideDefaultNoProxyEnvironmentIfNotSet() {
try (
BrowserWebDriverContainer chromeWithoutNoProxySet = new BrowserWebDriverContainer()
.withCapabilities(new ChromeOptions())
Expand All @@ -49,8 +49,8 @@ public void provideDefaultNoProxyEnvironmentIfNotSet() {
}

@Test
public void createContainerWithShmVolume() {
Assume.assumeFalse("SHM isn't mounted on Windows", SystemUtils.IS_OS_WINDOWS);
void createContainerWithShmVolume() {
assumeThat(SystemUtils.IS_OS_WINDOWS).isTrue();
try (
BrowserWebDriverContainer webDriverContainer = new BrowserWebDriverContainer()
.withCapabilities(new FirefoxOptions())
Expand All @@ -66,7 +66,7 @@ public void createContainerWithShmVolume() {
}

@Test
public void createContainerWithoutShmVolume() {
void createContainerWithoutShmVolume() {
try (
BrowserWebDriverContainer webDriverContainer = new BrowserWebDriverContainer<>()
.withSharedMemorySize(512 * FileUtils.ONE_MB)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package org.testcontainers.junit;

import com.google.common.io.PatternFilenameFilter;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.openqa.selenium.chrome.ChromeOptions;
import org.testcontainers.containers.BrowserWebDriverContainer;
import org.testcontainers.containers.BrowserWebDriverContainer.VncRecordingMode;
Expand All @@ -20,30 +18,31 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

import static org.assertj.core.api.Assertions.assertThat;

@RunWith(Enclosed.class)
public class ChromeRecordingWebDriverContainerTest extends BaseWebDriverContainerTest {
class ChromeRecordingWebDriverContainerTest extends BaseWebDriverContainerTest {

/**
* Guaranty a minimum video length for FFmpeg re-encoding.
* @see VncRecordingFormat#reencodeRecording(VncRecordingContainer, String)
*/
private static final int MINIMUM_VIDEO_DURATION_MILLISECONDS = 200;

public static class ChromeThatRecordsAllTests {
@Nested
class ChromeThatRecordsAllTests {

@Rule
public TemporaryFolder vncRecordingDirectory = new TemporaryFolder();
@TempDir
public Path vncRecordingDirectory;

@Test
public void recordingTestThatShouldBeRecordedAndRetainedInFlvFormatAsDefault() throws InterruptedException {
File target = vncRecordingDirectory.getRoot();
void recordingTestThatShouldBeRecordedAndRetainedInFlvFormatAsDefault() throws InterruptedException {
File target = vncRecordingDirectory.toFile();
try (
// recordAll {
// To do this, simply add extra parameters to the rule constructor, so video will default to FLV format:
Expand Down Expand Up @@ -80,12 +79,12 @@ public String getFilesystemFriendlyName() {
Optional.empty()
);

return vncRecordingDirectory.getRoot().listFiles(new PatternFilenameFilter(fileNamePattern));
return vncRecordingDirectory.toFile().listFiles(new PatternFilenameFilter(fileNamePattern));
}

@Test
public void recordingTestShouldHaveFlvExtension() throws InterruptedException {
File target = vncRecordingDirectory.getRoot();
void recordingTestShouldHaveFlvExtension() throws InterruptedException {
File target = vncRecordingDirectory.toFile();
try (
// recordFlv {
// Set (explicitly) FLV format for recorded video:
Expand All @@ -102,8 +101,8 @@ public void recordingTestShouldHaveFlvExtension() throws InterruptedException {
}

@Test
public void recordingTestShouldHaveMp4Extension() throws InterruptedException {
File target = vncRecordingDirectory.getRoot();
void recordingTestShouldHaveMp4Extension() throws InterruptedException {
File target = vncRecordingDirectory.toFile();
try (
// recordMp4 {
// Set MP4 format for recorded video:
Expand All @@ -120,12 +119,12 @@ public void recordingTestShouldHaveMp4Extension() throws InterruptedException {
}

@Test
public void recordingTestThatShouldHaveCorrectDuration() throws IOException, InterruptedException {
void recordingTestThatShouldHaveCorrectDuration() throws IOException, InterruptedException {
MountableFile mountableFile;
try (
BrowserWebDriverContainer<?> chrome = new BrowserWebDriverContainer<>()
.withCapabilities(new ChromeOptions())
.withRecordingMode(VncRecordingMode.RECORD_ALL, vncRecordingDirectory.getRoot())
.withRecordingMode(VncRecordingMode.RECORD_ALL, vncRecordingDirectory.toFile())
.withRecordingFileFactory(new DefaultRecordingFileFactory())
.withNetwork(NETWORK)
) {
Expand Down Expand Up @@ -159,13 +158,14 @@ public void recordingTestThatShouldHaveCorrectDuration() throws IOException, Int
}
}

public static class ChromeThatRecordsFailingTests {
@Nested
class ChromeThatRecordsFailingTests {

@Rule
public TemporaryFolder vncRecordingDirectory = new TemporaryFolder();
@TempDir
public Path vncRecordingDirectory;

@Test
public void recordingTestThatShouldBeRecordedButNotPersisted() {
void recordingTestThatShouldBeRecordedButNotPersisted() {
try (
// withRecordingFileFactory {
BrowserWebDriverContainer<?> chrome = new BrowserWebDriverContainer<>()
Expand All @@ -183,8 +183,8 @@ public void recordingTestThatShouldBeRecordedButNotPersisted() {
}

@Test
public void recordingTestThatShouldBeRecordedAndRetained() throws InterruptedException {
File target = vncRecordingDirectory.getRoot();
void recordingTestThatShouldBeRecordedAndRetained() throws InterruptedException {
File target = vncRecordingDirectory.toFile();
try (
// recordFailing {
// or if you only want videos for test failures:
Expand Down Expand Up @@ -214,11 +214,11 @@ public String getFilesystemFriendlyName() {
Optional.of(new RuntimeException("Force writing of video file."))
);

String[] files = vncRecordingDirectory.getRoot().list(new PatternFilenameFilter("FAILED-.*\\.flv"));
String[] files = vncRecordingDirectory.toFile().list(new PatternFilenameFilter("FAILED-.*\\.flv"));
assertThat(files).as("recorded file count").hasSize(1);
}
}

private static class CustomRecordingFileFactory extends DefaultRecordingFileFactory {}
class CustomRecordingFileFactory extends DefaultRecordingFileFactory {}
}
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
package org.testcontainers.junit;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.chrome.ChromeOptions;
import org.testcontainers.containers.BrowserWebDriverContainer;

/**
*
*/
public class ChromeWebDriverContainerTest extends BaseWebDriverContainerTest {
class ChromeWebDriverContainerTest extends BaseWebDriverContainerTest {

// junitRule {
@Rule
public BrowserWebDriverContainer<?> chrome = new BrowserWebDriverContainer<>()
.withCapabilities(new ChromeOptions())
// }
.withNetwork(NETWORK);

@Before
@BeforeEach
public void checkBrowserIsIndeedChrome() {
chrome.start();
assertBrowserNameIs(chrome, "chrome", new ChromeOptions());
}

@Test
public void simpleExploreTest() {
void simpleExploreTest() {
doSimpleExplore(chrome, new ChromeOptions());
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
package org.testcontainers.junit;

import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.AutoClose;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.chrome.ChromeOptions;
import org.testcontainers.containers.BrowserWebDriverContainer;

public class ContainerWithoutCapabilitiesTest extends BaseWebDriverContainerTest {
class ContainerWithoutCapabilitiesTest extends BaseWebDriverContainerTest {

@Rule
@AutoClose
public BrowserWebDriverContainer<?> chrome = new BrowserWebDriverContainer<>().withNetwork(NETWORK);

@BeforeEach
public void setUp() {
chrome.start();
}

@Test
public void chromeIsStartedIfNoCapabilitiesProvided() {
void chromeIsStartedIfNoCapabilitiesProvided() {
assertBrowserNameIs(chrome, "chrome", new ChromeOptions());
}

@Test
public void simpleExploreTestWhenNoCapabilitiesProvided() {
void simpleExploreTestWhenNoCapabilitiesProvided() {
doSimpleExplore(chrome, new ChromeOptions());
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
package org.testcontainers.junit;

import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.chrome.ChromeOptions;
import org.testcontainers.containers.BrowserWebDriverContainer;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

/**
*
*/
public class CustomWaitTimeoutWebDriverContainerTest extends BaseWebDriverContainerTest {
class CustomWaitTimeoutWebDriverContainerTest extends BaseWebDriverContainerTest {

@Rule
public BrowserWebDriverContainer<?> chromeWithCustomTimeout = new BrowserWebDriverContainer<>()
.withCapabilities(new ChromeOptions())
.withStartupTimeout(Duration.of(30, ChronoUnit.SECONDS))
.withNetwork(NETWORK);

@Test
public void simpleExploreTest() {
void simpleExploreTest() {
chromeWithCustomTimeout.start();
doSimpleExplore(chromeWithCustomTimeout, new ChromeOptions());
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
package org.testcontainers.junit;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.edge.EdgeOptions;
import org.testcontainers.containers.BrowserWebDriverContainer;

public class EdgeWebDriverContainerTest extends BaseWebDriverContainerTest {
class EdgeWebDriverContainerTest extends BaseWebDriverContainerTest {

// junitRule {
@Rule
public BrowserWebDriverContainer<?> edge = new BrowserWebDriverContainer<>()
.withCapabilities(new EdgeOptions())
// }
.withNetwork(NETWORK);

@Before
@BeforeEach
public void checkBrowserIsIndeedMSEdge() {
edge.start();
assertBrowserNameIs(edge, "msedge", new EdgeOptions());
}

@Test
public void simpleExploreTest() {
void simpleExploreTest() {
doSimpleExplore(edge, new EdgeOptions());
}
}
Loading
Loading