-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#303] fix framerate of gif and video recording and add tests for it
- Loading branch information
1 parent
e1897f0
commit 83aedce
Showing
13 changed files
with
269 additions
and
22 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
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
46 changes: 46 additions & 0 deletions
46
...est/java/com/xceptance/neodymium/junit4/testclasses/recording/AutomaticRecordingTest.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,46 @@ | ||
package com.xceptance.neodymium.junit4.testclasses.recording; | ||
|
||
import java.io.IOException; | ||
import java.util.UUID; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import com.codeborne.selenide.Selenide; | ||
import com.xceptance.neodymium.common.browser.Browser; | ||
import com.xceptance.neodymium.common.recording.FilmTestExecution; | ||
import com.xceptance.neodymium.junit4.NeodymiumRunner; | ||
|
||
@Browser("Chrome_headless") | ||
@RunWith(NeodymiumRunner.class) | ||
public class AutomaticRecordingTest | ||
{ | ||
public static String uuid; | ||
|
||
public static boolean isGif; | ||
|
||
@Test | ||
public void test() throws IOException | ||
{ | ||
uuid = UUID.randomUUID().toString(); | ||
if (isGif) | ||
{ | ||
FilmTestExecution.startGifRecording(uuid); | ||
} | ||
else | ||
{ | ||
FilmTestExecution.startVideoRecording(uuid); | ||
} | ||
Selenide.open("https://www.timeanddate.com/worldclock/germany/berlin"); | ||
Selenide.sleep(30000); | ||
|
||
if (isGif) | ||
{ | ||
FilmTestExecution.finishGifFilming(uuid, false); | ||
} | ||
else | ||
{ | ||
FilmTestExecution.finishVideoFilming(uuid, false); | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
.../java/com/xceptance/neodymium/junit4/tests/recording/automatic/RecordingDurationTest.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,73 @@ | ||
package com.xceptance.neodymium.junit4.tests.recording.automatic; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.aeonbits.owner.ConfigFactory; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.JUnitCore; | ||
|
||
import com.xceptance.neodymium.common.recording.FilmTestExecution; | ||
import com.xceptance.neodymium.common.recording.config.RecordingConfigurations; | ||
import com.xceptance.neodymium.junit4.testclasses.recording.AutomaticRecordingTest; | ||
import com.xceptance.neodymium.junit4.tests.NeodymiumTest; | ||
|
||
public class RecordingDurationTest extends NeodymiumTest | ||
{ | ||
public double runTest(boolean isGif, String oneImagePerMilliseconds) throws IOException | ||
{ | ||
AutomaticRecordingTest.isGif = isGif; | ||
String format = isGif ? "gif" : "video"; | ||
FilmTestExecution.clearThreadContexts(); | ||
Map<String, String> properties1 = new HashMap<>(); | ||
properties1.put(format + ".filmAutomatically", "false"); | ||
properties1.put(format + ".enableFilming", "true"); | ||
properties1.put(format + ".deleteRecordingsAfterAddingToAllureReport", "false"); | ||
properties1.put(format + ".oneImagePerMilliseconds", oneImagePerMilliseconds); | ||
final String fileLocation = "config/temp-" + format + "-" + oneImagePerMilliseconds + ".properties"; | ||
File tempConfigFile1 = new File("./" + fileLocation); | ||
writeMapToPropertiesFile(properties1, tempConfigFile1); | ||
ConfigFactory.setProperty(FilmTestExecution.TEMPORARY_CONFIG_FILE_PROPERTY_NAME, "file:" + fileLocation); | ||
tempFiles.add(tempConfigFile1); | ||
JUnitCore.runClasses(AutomaticRecordingTest.class); | ||
RecordingConfigurations config = isGif ? FilmTestExecution.getContextGif() : FilmTestExecution.getContextVideo(); | ||
File recordingFile = new File(config.tempFolderToStoreRecording() + AutomaticRecordingTest.uuid + "." + config.format()); | ||
recordingFile.deleteOnExit(); | ||
Assert.assertTrue("the recording file doesn't exist", recordingFile.exists()); | ||
ProcessBuilder pb = new ProcessBuilder("ffprobe", "-v", "error", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", recordingFile.getAbsolutePath()); | ||
pb.redirectErrorStream(true); | ||
Process p = pb.start(); | ||
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream())); | ||
String recordDuration = null; | ||
for (String line = r.readLine(); StringUtils.isNotBlank(line); line = r.readLine()) | ||
{ | ||
recordDuration = line; | ||
continue; | ||
} | ||
return Double.parseDouble(recordDuration); | ||
} | ||
|
||
@Test | ||
public void testVideoRecording() throws IOException | ||
{ | ||
double run1000 = runTest(false, "1000"); | ||
double run1500 = runTest(false, "1500"); | ||
Assert.assertEquals("Videos with different oneImagePerMilliseconds value should have approximaty the same length (1/1000 = " + run1000 + ", 1/1500 = " | ||
+ run1500 + ")", run1000, run1500, 5.0); | ||
} | ||
|
||
@Test | ||
public void testGifRecording() throws IOException | ||
{ | ||
double run1000 = runTest(true, "1000"); | ||
double run1500 = runTest(true, "1500"); | ||
Assert.assertEquals("Gifs with different oneImagePerMilliseconds value should have approximaty the same length (1/1000 = " + run1000 + ", 1/1500 = " | ||
+ run1500 + ")", run1000, run1500, 5.0); | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
...est/java/com/xceptance/neodymium/junit5/testclasses/recording/AutomaticRecordingTest.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,42 @@ | ||
package com.xceptance.neodymium.junit5.testclasses.recording; | ||
|
||
import java.io.IOException; | ||
import java.util.UUID; | ||
|
||
import com.codeborne.selenide.Selenide; | ||
import com.xceptance.neodymium.common.browser.Browser; | ||
import com.xceptance.neodymium.common.recording.FilmTestExecution; | ||
import com.xceptance.neodymium.junit5.NeodymiumTest; | ||
|
||
@Browser("Chrome_headless") | ||
public class AutomaticRecordingTest | ||
{ | ||
public static String uuid; | ||
|
||
public static boolean isGif; | ||
|
||
@NeodymiumTest | ||
public void test() throws IOException | ||
{ | ||
uuid = UUID.randomUUID().toString(); | ||
if (isGif) | ||
{ | ||
FilmTestExecution.startGifRecording(uuid); | ||
} | ||
else | ||
{ | ||
FilmTestExecution.startVideoRecording(uuid); | ||
} | ||
Selenide.open("https://www.timeanddate.com/worldclock/germany/berlin"); | ||
Selenide.sleep(30000); | ||
|
||
if (isGif) | ||
{ | ||
FilmTestExecution.finishGifFilming(uuid, false); | ||
} | ||
else | ||
{ | ||
FilmTestExecution.finishVideoFilming(uuid, false); | ||
} | ||
} | ||
} |
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
72 changes: 72 additions & 0 deletions
72
.../java/com/xceptance/neodymium/junit5/tests/recording/automatic/RecordingDurationTest.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,72 @@ | ||
package com.xceptance.neodymium.junit5.tests.recording.automatic; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.aeonbits.owner.ConfigFactory; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.junit.Assert; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import com.xceptance.neodymium.common.recording.FilmTestExecution; | ||
import com.xceptance.neodymium.common.recording.config.RecordingConfigurations; | ||
import com.xceptance.neodymium.junit5.testclasses.recording.AutomaticRecordingTest; | ||
import com.xceptance.neodymium.junit5.tests.AbstractNeodymiumTest; | ||
|
||
public class RecordingDurationTest extends AbstractNeodymiumTest | ||
{ | ||
public double runTest(boolean isGif, String oneImagePerMilliseconds) throws IOException | ||
{ | ||
AutomaticRecordingTest.isGif = isGif; | ||
String format = isGif ? "gif" : "video"; | ||
FilmTestExecution.clearThreadContexts(); | ||
Map<String, String> properties1 = new HashMap<>(); | ||
properties1.put(format + ".filmAutomatically", "false"); | ||
properties1.put(format + ".enableFilming", "true"); | ||
properties1.put(format + ".deleteRecordingsAfterAddingToAllureReport", "false"); | ||
properties1.put(format + ".oneImagePerMilliseconds", oneImagePerMilliseconds); | ||
final String fileLocation = "config/temp-" + format + "-" + oneImagePerMilliseconds + ".properties"; | ||
File tempConfigFile1 = new File("./" + fileLocation); | ||
writeMapToPropertiesFile(properties1, tempConfigFile1); | ||
ConfigFactory.setProperty(FilmTestExecution.TEMPORARY_CONFIG_FILE_PROPERTY_NAME, "file:" + fileLocation); | ||
tempFiles.add(tempConfigFile1); | ||
run(AutomaticRecordingTest.class); | ||
RecordingConfigurations config = isGif ? FilmTestExecution.getContextGif() : FilmTestExecution.getContextVideo(); | ||
File recordingFile = new File(config.tempFolderToStoreRecording() + AutomaticRecordingTest.uuid + "." + config.format()); | ||
recordingFile.deleteOnExit(); | ||
Assert.assertTrue("the recording file doesn't exist", recordingFile.exists()); | ||
ProcessBuilder pb = new ProcessBuilder("ffprobe", "-v", "error", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", recordingFile.getAbsolutePath()); | ||
pb.redirectErrorStream(true); | ||
Process p = pb.start(); | ||
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream())); | ||
String recordDuration = null; | ||
for (String line = r.readLine(); StringUtils.isNotBlank(line); line = r.readLine()) | ||
{ | ||
recordDuration = line; | ||
continue; | ||
} | ||
return Double.parseDouble(recordDuration); | ||
} | ||
|
||
@Test | ||
public void testVideoRecording() throws IOException | ||
{ | ||
double run1000 = runTest(false, "1000"); | ||
double run1500 = runTest(false, "1500"); | ||
Assert.assertEquals("Videos with different oneImagePerMilliseconds value should have approximaty the same length (1/1000 = " + run1000 + ", 1/1500 = " | ||
+ run1500 + ")", run1000, run1500, 5.0); | ||
} | ||
|
||
@Test | ||
public void testGifRecording() throws IOException | ||
{ | ||
double run1000 = runTest(true, "1000"); | ||
double run1500 = runTest(true, "1500"); | ||
Assert.assertEquals("Gifs with different oneImagePerMilliseconds value should have approximaty the same length (1/1000 = " + run1000 + ", 1/1500 = " | ||
+ run1500 + ")", run1000, run1500, 5.0); | ||
} | ||
} |
Oops, something went wrong.