forked from testcontainers/testcontainers-java
-
Notifications
You must be signed in to change notification settings - Fork 0
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
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 testcontainers#500.
- Loading branch information
Showing
5 changed files
with
103 additions
and
9 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
24 changes: 24 additions & 0 deletions
24
...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,24 @@ | ||
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"); | ||
|
||
@Override | ||
public File recordingFileForTest(File vncRecordingDirectory, Description description, boolean succeeded) { | ||
final String prefix = succeeded ? "PASSED" : "FAILED"; | ||
final String fileName = String.format("%s-%s-%s-%s.flv", | ||
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); | ||
} |
57 changes: 57 additions & 0 deletions
57
...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,57 @@ | ||
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.io.IOException; | ||
import java.nio.file.Files; | ||
import java.text.SimpleDateFormat; | ||
import java.util.*; | ||
|
||
import static java.lang.Boolean.FALSE; | ||
import static java.lang.Boolean.TRUE; | ||
import static java.lang.String.format; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.runner.Description.createTestDescription; | ||
|
||
@RunWith(Parameterized.class) | ||
@Value | ||
public class DefaultRecordingFileFactoryTest { | ||
|
||
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("YYYYMMdd-HHmmss"); | ||
|
||
|
||
@Parameterized.Parameters | ||
public static Collection<Object[]> data() { | ||
Random random = new Random(); | ||
return new ArrayList<Object[]>() {{ | ||
add(new Object[]{format("testMethodName%d", random.nextInt()), "FAILED", FALSE}); | ||
add(new Object[]{format("testMethodName%d", random.nextInt()), "PASSED", TRUE}); | ||
}}; | ||
} | ||
|
||
private final DefaultRecordingFileFactory factory = new DefaultRecordingFileFactory(); | ||
private final String methodName; | ||
private final String prefix; | ||
private final boolean success; | ||
|
||
@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); | ||
|
||
File expectedFile = new File(vncRecordingDirectory, format("%s-%s-%s-%s.flv", | ||
prefix, | ||
getClass().getSimpleName(), | ||
methodName, | ||
DATE_FORMAT.format(new Date())) | ||
); | ||
assertEquals(expectedFile, 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