Skip to content

VNC Recording does not work with JUnit 5 #1341

Open

Description

@ikos23

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

Activity

  1. bsideup commented on Mar 26, 2019

    @bsideup
    Member

    Hi @ikos23,

    FYI #1326 should fix it

  2. roamingthings commented on Mar 27, 2019

    @roamingthings
    Contributor

    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.

  3. stale commented on Jun 25, 2019

    @stale

    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.

  4. roamingthings commented on Jun 25, 2019

    @roamingthings
    Contributor

    Should this issue be closed?

  5. heruan commented on Sep 10, 2019

    @heruan

    Should this issue be closed?

    I'm still unable to record videos in JUnit 5 tests, so I guess this is still open.

  6. StasKolodyuk commented on Nov 2, 2019

    @StasKolodyuk

    Currently I'm using the following workaround

    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")));
    
  7. roamingthings commented on Nov 2, 2019

    @roamingthings
    Contributor

    The issue should be addressed by #1326

  8. tyge68 commented on Dec 23, 2019

    @tyge68

    @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 ?

  9. roamingthings commented on Dec 24, 2019

    @roamingthings
    Contributor

    @tyge68 Unfortunately i don't know either when the PR becomes part of the release but I hope that it will be accepted soon.

  10. stale commented on Mar 23, 2020

    @stale

    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.

  11. joerg-pfruender commented on Mar 29, 2020

    @joerg-pfruender

    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

  12. roamingthings commented on Mar 30, 2020

    @roamingthings
    Contributor

    @joerg-pfruender Did you also look at #1326 ? This solves the general problem notification of Testcontainers in JUint 5.

  13. joerg-pfruender commented on Mar 30, 2020

    @joerg-pfruender

    @roamingthings Sorry, I did not see that. Would be great to have that.

  14. roamingthings commented on Mar 30, 2020

    @roamingthings
    Contributor

    @joerg-pfruender As you might have seen it's not an easy task.

  15. TheHaf commented on Apr 17, 2020

    @TheHaf
    Contributor

    As #1326 was merged into the new release 1.14.0, does this mean that this issue is resolved?

  16. added this to the next milestone on Apr 17, 2020
  17. bsideup commented on Apr 17, 2020

    @bsideup
    Member

    @TheHaf it does! Please test :)

  18. joerg-pfruender commented on Apr 17, 2020

    @joerg-pfruender

    @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...

  19. modified the milestones: 1.14.2, next on May 21, 2020
  20. modified the milestones: next, 1.14.2 on May 28, 2020
  21. sharath2106 commented on Sep 19, 2020

    @sharath2106

    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.

  22. joerg-pfruender commented on Sep 19, 2020

    @joerg-pfruender

    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

  23. bsideup commented on Sep 20, 2020

    @bsideup
    Member

    @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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions