testcontainers-java: VNC Recording does not work with JUnit 5
When I have a plain old JUnit 4 test where I am using @Rule :
@Rule
public BrowserWebDriverContainer chrome = new BrowserWebDriverContainer()
.withCapabilities(new ChromeOptions())
.withRecordingMode(VncRecordingMode.RECORD_ALL, new File("./target/"))
.withRecordingFileFactory(new DefaultRecordingFileFactory());
Everything works fine. I am getting this in the logs:
Selenium remote URL is: http://localhost:32873/wd/hub VNC URL is: vnc://vnc:secret@localhost:32872 [main] INFO org.testcontainers.containers.BrowserWebDriverContainer - Screen recordings for test com.foo.bar.ChromeWebDriverContainerTest-simpleExploreTest will be stored at: .\target\PASSED-com.foo.bar.ChromeWebDriverContainerTest-simpleExploreTest-20190326-162333.flv The file is there and that’s ok.
But if I have JUnit 5 test where I am using @Testcontainers + @Container:
@Container
BrowserWebDriverContainer chrome = new BrowserWebDriverContainer()
.withCapabilities(new ChromeOptions())
.withRecordingMode(VncRecordingMode.RECORD_ALL, new File("./target/"))
.withRecordingFileFactory(new DefaultRecordingFileFactory());
The test is ok (passed), but there is no recording file. Nothing on the logs, just:
Selenium remote URL is: http://localhost:32873/wd/hub VNC URL is: vnc://vnc:secret@localhost:32872
About this issue
- Original URL
- State: open
- Created 5 years ago
- Comments: 20 (10 by maintainers)
Hi @ikos23,
FYI #1326 should fix it
The Issue is solved.
Your BrowserWebdriverContainer must be a field in the test, annotated with @Container to work with videos.
You should not start/stop the container in your code. That is done by hooks initialized by the @Testcontainers annotation. It scans for fields annotated with @Container and executes their start/stop methods. If you do not put your BrowserWebdriverContainer into a @Container annotated field and start/stop it on your own, then the framework can not inform the container if the test has failed and there will be no video on failing tests.
https://joerg-pfruender.github.io/software/testing/2020/03/29/testcontainers.html
https://github.com/joerg-pfruender/webdriver-testcontainers-junit5