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

Make default file recording directory of BrowserWebDriverContainer platform independent #2562

Merged
merged 4 commits into from Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -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";
public static final String TC_TEMP_DIR_PREFIX = "tc";
Copy link
Member

Choose a reason for hiding this comment

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

Private?

Copy link
Member Author

Choose a reason for hiding this comment

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

Of course, sorry.


@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.")));
}
}
}