Skip to content

Commit

Permalink
Regard specified VNC recording directory for BrowserWebDriverContaine…
Browse files Browse the repository at this point in the history
…r again
  • Loading branch information
Stefan Rempfer committed Apr 14, 2020
1 parent 7803597 commit 5f90aca
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
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,5 +1,7 @@
package org.testcontainers.junit;


import com.google.common.io.PatternFilenameFilter;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
Expand All @@ -11,23 +13,43 @@

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)
public class ChromeRecordingWebDriverContainerTest extends BaseWebDriverContainerTest {

public static class ChromeThatRecordsAllTests {

public File vncRecordingDirectory = new File("./build/");

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

@Test
public void recordingTestThatShouldBeRecordedAndRetained() {

final String testName = "ChromeThatRecordsAllTests-recordingTestThatShouldBeRecordedAndRetained-"
+ System.currentTimeMillis();

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

@Override
public String getFilesystemFriendlyName() {
return testName;
}
}, Optional.empty());

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

Expand Down

0 comments on commit 5f90aca

Please sign in to comment.