Best Testcontainers-java code snippet using org.testcontainers.junit.ChromeRecordingWebDriverContainerTest.recordingTestThatShouldBeRecordedAndRetained
Source:ChromeRecordingWebDriverContainerTest.java
...17 public static class ChromeThatRecordsAllTests {18 @Rule19 public TemporaryFolder vncRecordingDirectory = new TemporaryFolder();20 @Test21 public void recordingTestThatShouldBeRecordedAndRetained() {22 try (23 BrowserWebDriverContainer chrome = new BrowserWebDriverContainer()24 .withCapabilities(new ChromeOptions())25 .withRecordingMode(RECORD_ALL, vncRecordingDirectory.getRoot())26 .withRecordingFileFactory(new DefaultRecordingFileFactory())27 ) {28 chrome.start();29 doSimpleExplore(chrome);30 chrome.afterTest(new TestDescription() {31 @Override32 public String getTestId() {33 return getFilesystemFriendlyName();34 }35 @Override36 public String getFilesystemFriendlyName() {37 return "ChromeThatRecordsAllTests-recordingTestThatShouldBeRecordedAndRetained";38 }39 }, Optional.empty());40 String[] files = vncRecordingDirectory.getRoot().list(new PatternFilenameFilter("PASSED-.*\\.flv"));41 assertTrue("Recorded file not found", files.length == 1);42 }43 }44 }45 public static class ChromeThatRecordsFailingTests {46 @Rule47 public BrowserWebDriverContainer chrome = new BrowserWebDriverContainer()48 .withCapabilities(new ChromeOptions());49 @Test50 public void recordingTestThatShouldBeRecordedButNotPersisted() {51 doSimpleExplore(chrome);52 }53 @Test54 public void recordingTestThatShouldBeRecordedAndRetained() {55 doSimpleExplore(chrome);56 chrome.afterTest(new TestDescription() {57 @Override58 public String getTestId() {59 return getFilesystemFriendlyName();60 }61 @Override62 public String getFilesystemFriendlyName() {63 return "ChromeThatRecordsFailingTests-recordingTestThatShouldBeRecordedAndRetained";64 }65 }, Optional.of(new RuntimeException("Force writing of video file.")));66 }67 }68}...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!