You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
I've added a test to check the post-condition of a local container. However the test implementation is all but elegant. I've no idea on how to better test an extension like this.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe this is a mistake, please reply to this comment to keep it open. If there isn't one already, a PR to fix or at least reproduce the problem in a test case will always help us get back on track to tackle this.
public class Junit5VncRecoder implements TestWatcher {
@Override
public void testSuccessful(ExtensionContext context) {
CHROME_CONTAINER.afterTest(toTestDescription(context), Optional.empty());
}
@Override
public void testFailed(ExtensionContext context, Throwable cause) {
CHROME_CONTAINER.afterTest(toTestDescription(context), Optional.of(cause));
}
private static TestDescription toTestDescription(ExtensionContext context) {
return new TestDescription() {
@Override
public String getTestId() {
return context.getDisplayName();
}
@Override
public String getFilesystemFriendlyName() {
return context.getTestInstance().get().getClass().getSimpleName() + "-" + context.getTestMethod().get().getName();
}
};
}
}
@ExtendWith(Junit5VncRecoder.class)
@Testcontainers
public class BaseTest {
@Container
public static BrowserWebDriverContainer<?> CHROME_CONTAINER = new BrowserWebDriverContainer<>()
.withCapabilities(chromeOptions())
.withRecordingMode(BrowserWebDriverContainer.VncRecordingMode.RECORD_ALL, new File("./videos/"))
.withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger("chrome")));
@roamingthings I have tried with #1326 (cloned from this PR) then it passed (first I wrongly used above code still with the @ExtendWith(Junit5VncRecoder.class) ) but after it worked, is there a plan to release it soon ?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe this is a mistake, please reply to this comment to keep it open. If there isn't one already, a PR to fix or at least reproduce the problem in a test case will always help us get back on track to tackle this.
I hope c3d37e4 will soonly find its way to a release because currently the recorded videos are stored somewhere in a arbitrary temp folder and not in the specified folder.
On thing, I would like to have improved: The current implementation forces me to always initialize a container as a field in my test. But I often want to choose dynamically in different scenarios between a local webdriver (for debugging with the browser's developer tools), a remote webdriver or testcontainer's webdriver. The current implementation forces me: Always initialize and start testcontainers webdriver and get videos or choose dynamically and get no videos. Maybe I am the only person in the world with that requirements. If not, I will try think about a solution...
Is the issue resolved? I still face issues with video recording after test execution. I'm using TestNG instead of JUnit.
public BrowserWebDriverContainer chrome = new BrowserWebDriverContainer() .withCapabilities(new ChromeOptions().addArguments("--start-maximized")) .withRecordingMode(RECORD_ALL, new File("./target/"));
I'm currently using 1.14.3 version of Testcontainer <dependency> <groupId>org.testcontainers</groupId> <artifactId>selenium</artifactId> <version>1.14.3</version> <scope>compile</scope> </dependency>
Please let me know if there's anything I could do to make this work.
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.
@sharath2106 the feature is implemented for JUnit 5. If you're using an unsupported framework (like TestNG), you need to handle the test lifecycle yourself (see TestLifecycleAware interface)
Activity
bsideup commentedon Mar 26, 2019
Hi @ikos23,
FYI #1326 should fix it
roamingthings commentedon Mar 27, 2019
I've added a test to check the post-condition of a local container. However the test implementation is all but elegant. I've no idea on how to better test an extension like this.
stale commentedon Jun 25, 2019
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe this is a mistake, please reply to this comment to keep it open. If there isn't one already, a PR to fix or at least reproduce the problem in a test case will always help us get back on track to tackle this.
roamingthings commentedon Jun 25, 2019
Should this issue be closed?
heruan commentedon Sep 10, 2019
I'm still unable to record videos in JUnit 5 tests, so I guess this is still open.
StasKolodyuk commentedon Nov 2, 2019
Currently I'm using the following workaround
roamingthings commentedon Nov 2, 2019
The issue should be addressed by #1326
tyge68 commentedon Dec 23, 2019
@roamingthings I have tried with #1326 (cloned from this PR) then it passed (first I wrongly used above code still with the @ExtendWith(Junit5VncRecoder.class) ) but after it worked, is there a plan to release it soon ?
roamingthings commentedon Dec 24, 2019
@tyge68 Unfortunately i don't know either when the PR becomes part of the release but I hope that it will be accepted soon.
stale commentedon Mar 23, 2020
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe this is a mistake, please reply to this comment to keep it open. If there isn't one already, a PR to fix or at least reproduce the problem in a test case will always help us get back on track to tackle this.
joerg-pfruender commentedon Mar 29, 2020
I have a slightly different solution than @StasKolodyuk . @StasKolodyuk ist super straightforward but it will cause problems when you want to run multiple tests in parallel. If you need parallel test, you may check out my workaround from
https://joerg-pfruender.github.io/software/testing/2020/03/29/testcontainers.html
https://github.com/joerg-pfruender/webdriver-testcontainers-junit5
roamingthings commentedon Mar 30, 2020
@joerg-pfruender Did you also look at #1326 ? This solves the general problem notification of Testcontainers in JUint 5.
joerg-pfruender commentedon Mar 30, 2020
@roamingthings Sorry, I did not see that. Would be great to have that.
roamingthings commentedon Mar 30, 2020
@joerg-pfruender As you might have seen it's not an easy task.
TheHaf commentedon Apr 17, 2020
As #1326 was merged into the new release 1.14.0, does this mean that this issue is resolved?
bsideup commentedon Apr 17, 2020
@TheHaf it does! Please test :)
joerg-pfruender commentedon Apr 17, 2020
@roamingthings @bsideup @TheHaf Thank you very much for your efforts.
I hope c3d37e4 will soonly find its way to a release because currently the recorded videos are stored somewhere in a arbitrary temp folder and not in the specified folder.
On thing, I would like to have improved: The current implementation forces me to always initialize a container as a field in my test. But I often want to choose dynamically in different scenarios between a local webdriver (for debugging with the browser's developer tools), a remote webdriver or testcontainer's webdriver. The current implementation forces me: Always initialize and start testcontainers webdriver and get videos or choose dynamically and get no videos. Maybe I am the only person in the world with that requirements. If not, I will try think about a solution...
sharath2106 commentedon Sep 19, 2020
Is the issue resolved? I still face issues with video recording after test execution. I'm using TestNG instead of JUnit.
public BrowserWebDriverContainer chrome = new BrowserWebDriverContainer() .withCapabilities(new ChromeOptions().addArguments("--start-maximized")) .withRecordingMode(RECORD_ALL, new File("./target/"));@Override protected void createDriver() { chrome.start(); driver = chrome.getWebDriver(); }I'm currently using 1.14.3 version of Testcontainer
<dependency> <groupId>org.testcontainers</groupId> <artifactId>selenium</artifactId> <version>1.14.3</version> <scope>compile</scope> </dependency>Please let me know if there's anything I could do to make this work.
joerg-pfruender commentedon Sep 19, 2020
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
bsideup commentedon Sep 20, 2020
@sharath2106 the feature is implemented for JUnit 5. If you're using an unsupported framework (like TestNG), you need to handle the test lifecycle yourself (see
TestLifecycleAwareinterface)