I want to use one container for all tests in class (starting and stopping takes some time). It seems that when I use @ClassRule instead of @Rule, RECORD_FAILED doesn't record anything, so I need to use RECORD_ALL. It seems to be a JUnit issue, for @ClassRules it seems to not throw any exception even if test fails.
Maybe some other way of creating one container per test class would be needed? Or at least some warning in JavaDocs maybe?
Noobie here!
What are RECORD_FAILED and RECORD_ALL ?
@iirekm that's a good point - as is, the detection is limited and I can see how that would be frustrating. There _might_ be a way to make it possible, but I'm not sure of a clean way to do it just yet.
@martin-g this is the recording behaviour for selenium/webdriver containers - they can automatically record video of every test. RECORD_FAILED only keeps a video of the test methods that failed, whereas RECORD_ALL keeps all videos.
Let's update the docs to make this clearer.
I agree with this feature.
One way I think is possible is to add 2 public methods that starts and stop a recorder and a driver if needed :
startDriver / stopDriver
and to call them in test with @Before and @After
I'll see if I can make a PR.
@javathought PR is 鉂わ笍 馃憤
After some investigation, I changed the strategy to use a TestWatcher :
it can be used like this, and if no watcher given, it will work as previous (one video for the whole class)
@ClassRule
public static BrowserWebDriverContainer chrome = new BrowserWebDriverContainer()
.withDesiredCapabilities(DesiredCapabilities.chrome())
.withRecordingMode(RECORD_ALL, new File("target"));
@Rule
public ContainerWatcher watcher = new ContainerWatcher(chrome);
But for the moment, I now only have one BrowserWebDriverContainer but
I have to start a new VncRecordingContainer for each test, so I have a video per test and so can have only videos for failing tests and not all the Class.
It needs improvements to VncRecordingContainer to create several videos recordings. I don't see methods on DockerClient to interact with the container to call a new cmd (and call flvrec.py for a new recording).
@javathought I don't see why starting a new VncRecordingContainer for each test is bad BTW. Something like this (working code with TC 1.5.1+):
static File recordingDir = new File("build/recording-" + System.currentTimeMillis());
@ClassRule
public static BrowserWebDriverContainer chrome = new BrowserWebDriverContainer<>()
.withDesiredCapabilities(DesiredCapabilities.chrome())
.withNetwork(Network.SHARED)
.withNetworkAliases("vnchost")
.withRecordingMode(BrowserWebDriverContainer.VncRecordingMode.SKIP, null);
@Rule
public VncRecordingContainer vnc = new VncRecordingContainer(chrome);
@Rule
public TestName testName = new TestName();
@After
public void tearDown() throws Exception {
try(InputStream inputStream = vnc.streamRecording()) {
File target = new File(recordingDir, testName.getMethodName() + ".flv");
target.getParentFile().mkdirs();
Files.copy(inputStream, target.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
}
Starting a new VncRecordingContainer isn't bad for the test itself but if you have many tests, it will slow your overall test time (starting and stopping takes some time). The fastest they are, more they will be run (more by developer, or more test with your CI).
So ideally, the container should be able to make multiples recordings.
The problem with @After is that you don't know the result of your test, so you can't choose to save the recording on success/failure. It's why I choose a TestWatcher.
I've made the proof. It needs some code cleanup before sending th PR.
Here is an example how to achieve the proposed use case (as discussed in #577 by @bsideup):
static File recordingDir = new File("build/recording-" + System.currentTimeMillis());
@ClassRule
public static BrowserWebDriverContainer chrome = new BrowserWebDriverContainer<>()
.withDesiredCapabilities(DesiredCapabilities.chrome())
.withNetwork(Network.SHARED)
.withNetworkAliases("vnchost")
.withRecordingMode(BrowserWebDriverContainer.VncRecordingMode.SKIP, null);
@Rule
public VncRecordingContainer vnc = new VncRecordingContainer(chrome) {
@Override
protected void failed(Throwable e, Description description) {
saveRecordingToFile(new File(recordingDir, description.getMethodName() + ".flv"));
super.failed(e, description);
}
};