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

Regard specified VNC recording directory for BrowserWebDriverContainer again #2574

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -143,12 +143,15 @@ protected void configure() {
}

if (recordingMode != VncRecordingMode.SKIP) {
try {
vncRecordingDirectory = Files.createTempDirectory(TC_TEMP_DIR_PREFIX).toFile();
} catch (IOException e) {
// should never happen as per javadoc, since we use valid prefix
logger().error("Exception while trying to create temp directory " + vncRecordingDirectory.getAbsolutePath(), e);
throw new ContainerLaunchException("Exception while trying to create temp directory", e);

if (vncRecordingDirectory == null) {
try {
vncRecordingDirectory = Files.createTempDirectory(TC_TEMP_DIR_PREFIX).toFile();
} catch (IOException e) {
// should never happen as per javadoc, since we use valid prefix
logger().error("Exception while trying to create temp directory " + vncRecordingDirectory.getAbsolutePath(), e);
throw new ContainerLaunchException("Exception while trying to create temp directory", e);
}
}

if (getNetwork() == null) {
Expand Down
@@ -1,17 +1,19 @@
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.openqa.selenium.chrome.ChromeOptions;
import org.testcontainers.containers.BrowserWebDriverContainer;
import org.testcontainers.containers.DefaultRecordingFileFactory;
import org.testcontainers.lifecycle.TestDescription;

import java.io.File;
import java.util.Optional;

import static org.junit.Assert.assertTrue;
import static org.testcontainers.containers.BrowserWebDriverContainer.VncRecordingMode.RECORD_ALL;

@RunWith(Enclosed.class)
Expand All @@ -20,14 +22,34 @@ public class ChromeRecordingWebDriverContainerTest extends BaseWebDriverContaine
public static class ChromeThatRecordsAllTests {

@Rule
public BrowserWebDriverContainer chrome = new BrowserWebDriverContainer()
.withCapabilities(new ChromeOptions())
.withRecordingMode(RECORD_ALL, new File("./build/"))
.withRecordingFileFactory(new DefaultRecordingFileFactory());
public TemporaryFolder vncRecordingDirectory = new TemporaryFolder();

@Test
public void recordingTestThatShouldBeRecordedAndRetained() {
doSimpleExplore(chrome);
try (
BrowserWebDriverContainer chrome = new BrowserWebDriverContainer()
.withCapabilities(new ChromeOptions())
.withRecordingMode(RECORD_ALL, vncRecordingDirectory.getRoot())
.withRecordingFileFactory(new DefaultRecordingFileFactory())
) {
chrome.start();

doSimpleExplore(chrome);
chrome.afterTest(new TestDescription() {
@Override
public String getTestId() {
return getFilesystemFriendlyName();
}

@Override
public String getFilesystemFriendlyName() {
return "ChromeThatRecordsAllTests-recordingTestThatShouldBeRecordedAndRetained";
}
}, Optional.empty());

String[] files = vncRecordingDirectory.getRoot().list(new PatternFilenameFilter("PASSED-.*\\.flv"));
assertTrue("Recorded file not found", files.length == 1);
}
}
}

Expand Down