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

VNC Recording does not work with JUnit 5 #1341

Open
ikos23 opened this issue Mar 26, 2019 · 20 comments
Open

VNC Recording does not work with JUnit 5 #1341

ikos23 opened this issue Mar 26, 2019 · 20 comments

Comments

@ikos23
Copy link

ikos23 commented Mar 26, 2019

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

@bsideup
Copy link
Member

bsideup commented Mar 26, 2019

Hi @ikos23,

FYI #1326 should fix it

@roamingthings
Copy link
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.

@stale
Copy link

stale bot commented 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.

@stale stale bot added the stale label Jun 25, 2019
@roamingthings
Copy link
Contributor

Should this issue be closed?

@heruan
Copy link

heruan commented Sep 10, 2019

Should this issue be closed?

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

@StasKolodyuk
Copy link

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")));

@roamingthings
Copy link
Contributor

The issue should be addressed by #1326

@tyge68
Copy link

tyge68 commented 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
Copy link
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.

@stale
Copy link

stale bot commented 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.

@stale stale bot added the stale label Mar 23, 2020
@stale stale bot removed the stale label Mar 23, 2020
@joerg-pfruender
Copy link

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
Copy link
Contributor

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

@joerg-pfruender
Copy link

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

@roamingthings
Copy link
Contributor

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

@TheHaf
Copy link
Contributor

TheHaf commented Apr 17, 2020

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

@bsideup bsideup added this to the next milestone Apr 17, 2020
@bsideup
Copy link
Member

bsideup commented Apr 17, 2020

@TheHaf it does! Please test :)

@joerg-pfruender
Copy link

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

@rnorth rnorth modified the milestones: 1.14.2, next May 21, 2020
@bsideup bsideup modified the milestones: next, 1.14.2 May 28, 2020
@sharath2106
Copy link

sharath2106 commented 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
Copy link

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
Copy link
Member

bsideup commented 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 TestLifecycleAware interface)

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

No branches or pull requests

10 participants