-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RecordingFileFactory with default implementation (#507)
Add RecordingFileFactory with default implementation By default this returns a file in the given vlc recording directory named '<RESULT>-<TestClassName>-<testMethodName>-<YYYYMMdd-HHmmss>.flv', where RESULT is either 'PASSED' or 'FAILED'. A custom factory can be provided to BrowserWebDriverContainer#withRecordingFileFactory. The factory is only applicable if the BrowserWebDriverContainer#recordingMode enables the retention of recordings. Fixes #500.
- Loading branch information
Showing
7 changed files
with
119 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...les/selenium/src/main/java/org/testcontainers/containers/DefaultRecordingFileFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.testcontainers.containers; | ||
|
||
import org.junit.runner.Description; | ||
|
||
import java.io.File; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
public class DefaultRecordingFileFactory implements RecordingFileFactory { | ||
|
||
private static final SimpleDateFormat filenameDateFormat = new SimpleDateFormat("YYYYMMdd-HHmmss"); | ||
private static final String PASSED = "PASSED"; | ||
private static final String FAILED = "FAILED"; | ||
private static final String FILENAME_FORMAT = "%s-%s-%s-%s.flv"; | ||
|
||
@Override | ||
public File recordingFileForTest(File vncRecordingDirectory, Description description, boolean succeeded) { | ||
final String prefix = succeeded ? PASSED : FAILED; | ||
final String fileName = String.format(FILENAME_FORMAT, | ||
prefix, | ||
description.getTestClass().getSimpleName(), | ||
description.getMethodName(), | ||
filenameDateFormat.format(new Date()) | ||
); | ||
return new File(vncRecordingDirectory, fileName); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
modules/selenium/src/main/java/org/testcontainers/containers/RecordingFileFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.testcontainers.containers; | ||
|
||
import org.junit.runner.Description; | ||
|
||
import java.io.File; | ||
|
||
public interface RecordingFileFactory { | ||
File recordingFileForTest(File vncRecordingDirectory, Description description, boolean succeeded); | ||
} |
60 changes: 60 additions & 0 deletions
60
...selenium/src/test/java/org/testcontainers/containers/DefaultRecordingFileFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.testcontainers.containers; | ||
|
||
import lombok.Value; | ||
import org.junit.Test; | ||
import org.junit.runner.Description; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.io.File; | ||
import java.nio.file.Files; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
import static java.lang.Boolean.FALSE; | ||
import static java.lang.Boolean.TRUE; | ||
import static java.lang.String.format; | ||
import static java.time.LocalDateTime.now; | ||
import static org.hamcrest.core.IsCollectionContaining.hasItem; | ||
import static org.junit.Assert.assertThat; | ||
import static org.junit.runner.Description.createTestDescription; | ||
|
||
@RunWith(Parameterized.class) | ||
@Value | ||
public class DefaultRecordingFileFactoryTest { | ||
|
||
private static final DateTimeFormatter DATETIME_FORMATTER = DateTimeFormatter.ofPattern("YYYYMMdd-HHmmss"); | ||
|
||
private final DefaultRecordingFileFactory factory = new DefaultRecordingFileFactory(); | ||
private final String methodName; | ||
private final String prefix; | ||
private final boolean success; | ||
|
||
@Parameterized.Parameters | ||
public static Collection<Object[]> data() { | ||
Collection<Object[]> args = new ArrayList<>(); | ||
args.add(new Object[]{"testMethod1", "FAILED", FALSE}); | ||
args.add(new Object[]{"testMethod2", "PASSED", TRUE}); | ||
return args; | ||
} | ||
|
||
@Test | ||
public void recordingFileThatShouldDescribeTheTestResultAtThePresentTime() throws Exception { | ||
File vncRecordingDirectory = Files.createTempDirectory("recording").toFile(); | ||
Description description = createTestDescription(getClass().getCanonicalName(), methodName, Test.class); | ||
|
||
File recordingFile = factory.recordingFileForTest(vncRecordingDirectory, description, success); | ||
|
||
String expectedFilePrefix = format("%s-%s-%s", prefix, getClass().getSimpleName(), methodName); | ||
|
||
List<File> expectedPossibleFileNames = Arrays.asList( | ||
new File(vncRecordingDirectory, format("%s-%s.flv", expectedFilePrefix, now().format(DATETIME_FORMATTER))), | ||
new File(vncRecordingDirectory, format("%s-%s.flv", expectedFilePrefix, now().minusSeconds(1L).format(DATETIME_FORMATTER))) | ||
); | ||
|
||
assertThat(expectedPossibleFileNames, hasItem(recordingFile)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters