Home > Software design >  Quarkus and Selenium TestContainer- how to trigger recording
Quarkus and Selenium TestContainer- how to trigger recording

Time:03-05

I am having trouble getting Selenium TestContainers to record the tests for me.

I am using TestContainers in Quarkus. The Quarkus way to deal with setting up test resources in a QuarkusTestResourceLifecycleManager class, as such:

@Slf4j
@Testcontainers //not working
public class TestResourceLifecycleManager implements QuarkusTestResourceLifecycleManager {
    //...
    @Container //not working
    private static BrowserWebDriverContainer<?> BROWSER_CONTAINER = null;
    //...

    
    @Override
    public Map<String, String> start() {
        File recordingDir = new File("build/seleniumRecordings/");
            
        recordingDir.mkdir();
            
        BROWSER_CONTAINER = new BrowserWebDriverContainer<>()
            .withCapabilities(new FirefoxOptions())
            .withRecordingMode(RECORD_ALL, recordingDir);
        BROWSER_CONTAINER.start();
    }
}

This functionally works, as I am able to use Selenium through the test container and the tests work fine. However, the recordings are never triggered, as I am not setting up my browser container in the test class.

I have also attempted moving the testcontainer to a superclass for my UI tests. This seems to again functionally work, and the recording is obviously triggered, but I only get a single flv file with ~149kB and doesn't play anything (for around 10 separate UI tests). Additionally, this does not seem to play nicely with multi-profile tests (tests that swap profiles, restarting Quarkus and nuking static members), and the tests after the inital set in a different profile break.

@Slf4j
@Testcontainers
public class WebUiTest extends RunningServerTest implements TestLifecycleAware {
    
    private static final File recordingDir = new File("build/seleniumRecordings/");
    
    @SuppressWarnings({"unused", "FieldCanBeLocal", "FieldMayBeFinal"})
    @Container
    private static BrowserWebDriverContainer<?> BROWSER_CONTAINER = new BrowserWebDriverContainer<>()
        .withCapabilities(new FirefoxOptions())
        .withRecordingMode(RECORD_ALL, recordingDir);
    
    static {
        //required for tests to work
        BROWSER_CONTAINER.start();
    }
}

Any ideas? Best-case I would love to be able to trigger recording in a standard junit @AfterEach method, but the arguments required (TestDescription description, Optional<Throwable> throwable) aren't available...

CodePudding user response:

Best-case I would love to be able to trigger recording in a standard junit @AfterEach method, but the arguments required (TestDescription description, Optional throwable) aren't available...

This is what I would recommend for more advanced framework integrations that don't work OOTB. You should be able instatiate a TestDescription for your use case e.g., from an anonymous class (it is used to infer the recording's file name).

new TestDescription() {

   @Override
   String getTestId() {
     // can be null, is not used
     return null
   }

   @Override
   String getFilesystemFriendlyName() {
     return "myTestMethod";
   }
}
  • Related