Skip to content

Commit

Permalink
openvidu-test-e2e: fix video dimension tests. Add new pro test
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloFuente committed Apr 27, 2023
1 parent 0263521 commit 6479382
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3137,6 +3137,82 @@ void customLayoutBroadcastTest() throws Exception {
}
}

@Test
@DisplayName("Broadcast and composed recording Test")
void broadcastAndComposedRecordingTest() throws Exception {

log.info("Broadcast and composed recording Test");

try {
String BROADCAST_IP = TestUtils.startRtmpServer();

final String sessionName = "BROADCAST_AND_RECORDED_SESSION";

OpenViduTestappUser user = setupBrowserAndConnectToOpenViduTestapp("chrome");
user.getDriver().findElement(By.id("add-user-btn")).click();
user.getDriver().findElement(By.id("session-name-input-0")).clear();
user.getDriver().findElement(By.id("session-name-input-0")).sendKeys(sessionName);
user.getDriver().findElement(By.className("join-btn")).sendKeys(Keys.ENTER);
user.getEventManager().waitUntilEventReaches("streamCreated", 1);
user.getEventManager().waitUntilEventReaches("streamPlaying", 1);

user.getDriver().findElement(By.id("session-api-btn-0")).click();
Thread.sleep(750);
WebElement broadcastUrlField = user.getDriver().findElement(By.id("broadcasturl-id-field"));
broadcastUrlField.clear();
broadcastUrlField.sendKeys("rtmp://" + BROADCAST_IP + "/live");
user.getDriver().findElement(By.id("broadcast-properties-btn")).click();
Thread.sleep(500);

// Start broadcast
user.getDriver().findElement(By.id("start-broadcast-btn")).click();
user.getWaiter().until(
ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value", "Broadcast started"));
user.getEventManager().waitUntilEventReaches("broadcastStarted", 1);

// Start composed recording
user.getDriver().findElement(By.id("start-recording-btn")).click();
user.getWaiter().until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value",
"Recording started [" + sessionName + "]"));
user.getEventManager().waitUntilEventReaches("recordingStarted", 1);

Thread.sleep(2000);

// Check broadcast
checkRtmpRecordingIsFine(30, RecordingUtils::checkVideoAverageRgbGreen);

// Stop broadcast
user.getDriver().findElement(By.id("stop-broadcast-btn")).click();
user.getWaiter().until(
ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value", "Broadcast stopped"));
user.getEventManager().waitUntilEventReaches("broadcastStopped", 1);

// Stop recording
user.getDriver().findElement(By.id("recording-id-field")).clear();
user.getDriver().findElement(By.id("recording-id-field")).sendKeys(sessionName);
user.getDriver().findElement(By.id("stop-recording-btn")).click();
user.getWaiter().until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value",
"Recording stopped [" + sessionName + "]"));
user.getEventManager().waitUntilEventReaches("recordingStopped", 1);

// Check recording
String recordingsPath = "/opt/openvidu/recordings/";
File file1 = new File(recordingsPath + sessionName + "/" + sessionName + ".mp4");
File file2 = new File(recordingsPath + sessionName + "/" + sessionName + ".jpg");
Assertions.assertTrue(
this.recordingUtils.recordedGreenFileFine(file1,
new OpenVidu(OPENVIDU_URL, OPENVIDU_SECRET).getRecording(sessionName)),
"Recorded file " + file1.getAbsolutePath() + " is not fine");
Assertions.assertTrue(this.recordingUtils.thumbnailIsFine(file2, RecordingUtils::checkVideoAverageRgbGreen),
"Thumbnail " + file2.getAbsolutePath() + " is not fine");

gracefullyLeaveParticipants(user, 1);

} finally {
TestUtils.stopRtmpServer();
}
}

private void checkRtmpRecordingIsFine(long secondsTimeout, Function<Map<String, Long>, Boolean> colorCheckFunction)
throws InterruptedException {
final String broadcastRecordingPath = "/opt/openvidu/recordings";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1009,52 +1009,23 @@ void streamPropertyChangedEventTest() throws Exception {
}

// Resize captured window
final CountDownLatch latchViewport = new CountDownLatch(1);
final CountDownLatch latch3 = new CountDownLatch(2);
int newWidth = 1000;
int newHeight = 700;

final long[] expectedWidthHeight = new long[2];

user.getEventManager().on("streamPropertyChanged", (event) -> {
try {
if (latchViewport.await(4000, TimeUnit.MILLISECONDS)) {
// Using a local or dockerized browser may vary the height value in 1 unit
String expectedDimensions1 = "{\"width\":" + expectedWidthHeight[0] + ",\"height\":"
+ expectedWidthHeight[1] + "}";
String expectedDimensions2 = "{\"width\":" + expectedWidthHeight[0] + ",\"height\":"
+ (expectedWidthHeight[1] + 1) + "}";
System.out.println("Publisher dimensions: " + event.get("newValue").getAsJsonObject().toString());
System.out.println("Real dimensions of viewport (+0/+1 in height): " + expectedDimensions1);
if ("videoDimensions".equals(event.get("changedProperty").getAsString())
&& "screenResized".equals(event.get("reason").getAsString())
&& (expectedDimensions1.equals(event.get("newValue").getAsJsonObject().toString())
|| expectedDimensions2
.equals(event.get("newValue").getAsJsonObject().toString()))) {
latch3.countDown();
}
} else {
fail("Viewport resolution did not change in 4 seconds");
}
} catch (InterruptedException e) {
log.error("Error waiting for viewport resolution");
String expectedDimensions = "{\"width\":" + newWidth + ",\"height\":" + newHeight + "}";
System.out.println("Publisher dimensions: " + event.get("newValue").getAsJsonObject().toString());
System.out.println("Real dimensions of viewport: " + expectedDimensions);
if ("videoDimensions".equals(event.get("changedProperty").getAsString())
&& "screenResized".equals(event.get("reason").getAsString())
&& (expectedDimensions.equals(event.get("newValue").getAsJsonObject().toString()))) {
latch3.countDown();
}
});

user.getDriver().manage().window().setSize(new Dimension(newWidth, newHeight));

new Thread(() -> {
String widthAndHeight = user.getBrowserUser().getDimensionOfViewport();
JsonObject obj = JsonParser.parseString(widthAndHeight).getAsJsonObject();

expectedWidthHeight[0] = obj.get("width").getAsLong();
expectedWidthHeight[1] = obj.get("height").getAsLong();

System.out.println("New viewport dimension: " + obj.toString());
latchViewport.countDown();

}).start();

user.getEventManager().waitUntilEventReaches("streamPropertyChanged", 6);

if (!latch3.await(4000, TimeUnit.MILLISECONDS)) {
Expand Down Expand Up @@ -2669,7 +2640,9 @@ void openViduJavaClientTest() throws Exception {

OpenViduTestappUser user = setupBrowserAndConnectToOpenViduTestapp("chromeAlternateScreenShare");

user.getDriver().manage().window().setSize(new Dimension(1000, 800));
final int width = 1000;
final int height = 800;
user.getDriver().manage().window().setSize(new Dimension(width, height));

log.info("openvidu-java-client test");

Expand Down Expand Up @@ -2885,19 +2858,11 @@ void openViduJavaClientTest() throws Exception {
}
pub = connectionModerator.getPublishers().get(0);

String widthAndHeight = user.getBrowserUser().getDimensionOfViewport();
JsonObject obj = JsonParser.parseString(widthAndHeight).getAsJsonObject();

// Using a local or dockerized browser may vary the height value in 1 unit
long validHeight1 = obj.get("height").getAsLong();
long validHeight2 = validHeight1 + 1;
String validDimensions1 = "{\"width\":" + obj.get("width").getAsLong() + ",\"height\":" + validHeight1 + "}";
String validDimensions2 = "{\"width\":" + obj.get("width").getAsLong() + ",\"height\":" + validHeight2 + "}";
String validDimensions = "{\"width\":" + width + ",\"height\":" + height + "}";

Assertions.assertTrue(
validDimensions1.equals(pub.getVideoDimensions()) || validDimensions2.equals(pub.getVideoDimensions()),
"Wrong video dimenstions. Expected: " + validDimensions1 + "(+0/+1 in height) but actual: "
+ pub.getVideoDimensions());
Assertions.assertTrue(validDimensions.equals(pub.getVideoDimensions()),
"Wrong video dimensions. Expected: " + validDimensions + " but actual: " + pub.getVideoDimensions());

Assertions.assertEquals(Integer.valueOf(30), pub.getFrameRate());
Assertions.assertEquals("SCREEN", pub.getTypeOfVideo());
Expand Down

0 comments on commit 6479382

Please sign in to comment.