Skip to content

Commit

Permalink
Make default file recording directory of BrowserWebDriverContainer pl…
Browse files Browse the repository at this point in the history
…atform independent (testcontainers#2562)

Co-authored-by: Sergei Egorov <bsideup@gmail.com>
  • Loading branch information
2 people authored and quincy committed May 28, 2020
1 parent 4e612cd commit ea2052c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Expand Up @@ -28,8 +28,10 @@
import org.testcontainers.lifecycle.TestLifecycleAware;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.time.Duration;
import java.util.Optional;
import java.util.Set;
Expand All @@ -52,6 +54,7 @@ public class BrowserWebDriverContainer<SELF extends BrowserWebDriverContainer<SE
private static final int VNC_PORT = 5900;

private static final String NO_PROXY_KEY = "no_proxy";
private static final String TC_TEMP_DIR_PREFIX = "tc";

@Nullable
private Capabilities capabilities;
Expand All @@ -61,7 +64,7 @@ public class BrowserWebDriverContainer<SELF extends BrowserWebDriverContainer<SE
private RemoteWebDriver driver;
private VncRecordingMode recordingMode = VncRecordingMode.RECORD_FAILING;
private RecordingFileFactory recordingFileFactory;
private File vncRecordingDirectory = new File("/tmp");
private File vncRecordingDirectory;

private VncRecordingContainer vncRecordingContainer = null;

Expand Down Expand Up @@ -140,6 +143,14 @@ 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 (getNetwork() == null) {
withNetwork(Network.SHARED);
}
Expand Down
Expand Up @@ -7,8 +7,10 @@
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.testcontainers.containers.BrowserWebDriverContainer.VncRecordingMode.RECORD_ALL;

Expand Down Expand Up @@ -36,8 +38,24 @@ public static class ChromeThatRecordsFailingTests {
.withCapabilities(new ChromeOptions());

@Test
public void recordingTestThatShouldBeRecordedButDeleted() {
public void recordingTestThatShouldBeRecordedButNotPersisted() {
doSimpleExplore(chrome);
}

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

@Override
public String getFilesystemFriendlyName() {
return "ChromeThatRecordsFailingTests-recordingTestThatShouldBeRecordedAndRetained";
}
}, Optional.of(new RuntimeException("Force writing of video file.")));
}
}
}

0 comments on commit ea2052c

Please sign in to comment.