mirror of https://github.com/OpenVidu/openvidu.git
openvidu-test-e2e: check if remote record video is green
parent
3fd2039f91
commit
cab5138174
|
@ -1,4 +1,5 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -136,15 +137,26 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>${version.json-simple}</version>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>${version.json-simple}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>xml-apis</groupId>
|
||||
<artifactId>xml-apis</artifactId>
|
||||
<version>1.4.01</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jcodec</groupId>
|
||||
<artifactId>jcodec</artifactId>
|
||||
<version>0.2.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jcodec</groupId>
|
||||
<artifactId>jcodec-javase</artifactId>
|
||||
<version>0.2.3</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>io.openvidu</groupId>
|
||||
|
|
|
@ -38,6 +38,8 @@ import org.json.simple.parser.ParseException;
|
|||
import org.openqa.selenium.JavascriptExecutor;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Manager event class for BrowserUser. Collects, cleans and stores events from
|
||||
|
@ -47,6 +49,8 @@ import org.openqa.selenium.WebElement;
|
|||
* @since 1.1.1
|
||||
*/
|
||||
public class OpenViduEventManager {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(OpenViduEventManager.class);
|
||||
|
||||
private static class RunnableCallback implements Runnable {
|
||||
|
||||
|
@ -172,7 +176,7 @@ public class OpenViduEventManager {
|
|||
while (!this.eventQueue.isEmpty()) {
|
||||
JSONObject event = this.eventQueue.poll();
|
||||
|
||||
System.out.println(event.get("event") + ": " + event);
|
||||
log.info(event.get("event") + ": " + event);
|
||||
|
||||
if (this.eventCallbacks.containsKey(event.get("event"))) {
|
||||
for (RunnableCallback callback : this.eventCallbacks.get(event.get("event"))) {
|
||||
|
|
|
@ -17,15 +17,17 @@
|
|||
|
||||
package io.openvidu.test.e2e;
|
||||
|
||||
import static java.lang.invoke.MethodHandles.lookup;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.openqa.selenium.OutputType.BASE64;
|
||||
import static org.slf4j.LoggerFactory.getLogger;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -34,6 +36,10 @@ import java.util.concurrent.ConcurrentLinkedQueue;
|
|||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jcodec.api.FrameGrab;
|
||||
import org.jcodec.api.JCodecException;
|
||||
import org.jcodec.common.model.Picture;
|
||||
import org.jcodec.scale.AWTUtil;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
|
@ -56,9 +62,12 @@ import org.openqa.selenium.WebElement;
|
|||
import org.openqa.selenium.support.ui.ExpectedCondition;
|
||||
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import io.github.bonigarcia.SeleniumExtension;
|
||||
import io.github.bonigarcia.wdm.WebDriverManager;
|
||||
import io.openvidu.java.client.OpenVidu;
|
||||
import io.openvidu.java.client.Recording;
|
||||
import io.openvidu.test.e2e.browser.BrowserUser;
|
||||
import io.openvidu.test.e2e.browser.ChromeAndroidUser;
|
||||
import io.openvidu.test.e2e.browser.ChromeUser;
|
||||
|
@ -83,7 +92,7 @@ public class OpenViduTestAppE2eTest {
|
|||
static Exception ex = null;
|
||||
private final Object lock = new Object();
|
||||
|
||||
final static Logger log = getLogger(lookup().lookupClass());
|
||||
private static final Logger log = LoggerFactory.getLogger(OpenViduTestAppE2eTest.class);
|
||||
|
||||
BrowserUser user;
|
||||
|
||||
|
@ -940,8 +949,8 @@ public class OpenViduTestAppE2eTest {
|
|||
final long[] expectedWidthHeight = new long[2];
|
||||
|
||||
user.getEventManager().on("streamPropertyChanged", (event) -> {
|
||||
threadAssertions.add(((String) event.get("eventContent")).contains(
|
||||
"videoDimensions [{\"width\":" + expectedWidthHeight[0] + ",\"height\":" + expectedWidthHeight[1] + "}]"));
|
||||
threadAssertions.add(((String) event.get("eventContent")).contains("videoDimensions [{\"width\":"
|
||||
+ expectedWidthHeight[0] + ",\"height\":" + expectedWidthHeight[1] + "}]"));
|
||||
latch3.countDown();
|
||||
});
|
||||
|
||||
|
@ -1084,19 +1093,13 @@ public class OpenViduTestAppE2eTest {
|
|||
Thread.sleep(1000);
|
||||
user.getDriver().findElement(By.id("start-recording-btn")).click();
|
||||
|
||||
Thread.sleep(4000);
|
||||
|
||||
try {
|
||||
System.out.println(getBase64Screenshot(user));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
user.getWaiter().until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value",
|
||||
"Recording started [" + sessionName + "]"));
|
||||
|
||||
user.getEventManager().waitUntilEventReaches("recordingStarted", 1);
|
||||
|
||||
Thread.sleep(8000);
|
||||
|
||||
user.getDriver().findElement(By.id("recording-id-field")).clear();
|
||||
user.getDriver().findElement(By.id("recording-id-field")).sendKeys(sessionName);
|
||||
|
||||
|
@ -1105,12 +1108,12 @@ public class OpenViduTestAppE2eTest {
|
|||
user.getWaiter()
|
||||
.until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value", "Error [409]"));
|
||||
|
||||
// Try to get a existing recording
|
||||
// Try to get an existing recording
|
||||
user.getDriver().findElement(By.id("get-recording-btn")).click();
|
||||
user.getWaiter().until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value",
|
||||
"Recording got [" + sessionName + "]"));
|
||||
|
||||
// Try to delete a ongoing recording
|
||||
// Try to delete an ongoing recording
|
||||
user.getDriver().findElement(By.id("delete-recording-btn")).click();
|
||||
user.getWaiter()
|
||||
.until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value", "Error [409]"));
|
||||
|
@ -1136,6 +1139,9 @@ public class OpenViduTestAppE2eTest {
|
|||
Assert.assertTrue(file2.exists() || file2.length() > 0);
|
||||
Assert.assertTrue(file3.exists() || file3.length() > 0);
|
||||
|
||||
Assert.assertTrue(
|
||||
this.recordedFileFine(file1, new OpenVidu(OPENVIDU_URL, OPENVIDU_SECRET).getRecording(sessionName)));
|
||||
|
||||
// Try to get the stopped recording
|
||||
user.getDriver().findElement(By.id("get-recording-btn")).click();
|
||||
user.getWaiter().until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value",
|
||||
|
@ -1613,4 +1619,44 @@ public class OpenViduTestAppE2eTest {
|
|||
return "data:image/png;base64," + screenshotBase64;
|
||||
}
|
||||
|
||||
private boolean recordedFileFine(File file, Recording recording) {
|
||||
boolean isFine = false;
|
||||
Picture frame;
|
||||
try {
|
||||
// Get a frame at 75% duration
|
||||
frame = FrameGrab.getFrameAtSec(file, (double) (recording.getDuration() * 0.75));
|
||||
Map<String, Long> colorMap = this.averageColor(AWTUtil.toBufferedImage(frame));
|
||||
log.info("Recording map color: {}", colorMap.toString());
|
||||
isFine = this.checkVideoAverageRgbGreen(colorMap);
|
||||
} catch (IOException | JCodecException e) {
|
||||
log.warn("Error getting frame from video recording: {}", e.getMessage());
|
||||
isFine = false;
|
||||
}
|
||||
return isFine;
|
||||
}
|
||||
|
||||
private Map<String, Long> averageColor(BufferedImage bi) {
|
||||
int x0 = 0;
|
||||
int y0 = 0;
|
||||
int w = bi.getWidth();
|
||||
int h = bi.getHeight();
|
||||
int x1 = x0 + w;
|
||||
int y1 = y0 + h;
|
||||
long sumr = 0, sumg = 0, sumb = 0;
|
||||
for (int x = x0; x < x1; x++) {
|
||||
for (int y = y0; y < y1; y++) {
|
||||
Color pixel = new Color(bi.getRGB(x, y));
|
||||
sumr += pixel.getRed();
|
||||
sumg += pixel.getGreen();
|
||||
sumb += pixel.getBlue();
|
||||
}
|
||||
}
|
||||
int num = w * h;
|
||||
Map<String, Long> colorMap = new HashMap<>();
|
||||
colorMap.put("r", (long) (sumr / num));
|
||||
colorMap.put("g", (long) (sumg / num));
|
||||
colorMap.put("b", (long) (sumb / num));
|
||||
return colorMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<include resource="org/springframework/boot/logging/logback/base.xml" />
|
||||
<logger name="io.openvidu.test.e2e" level="INFO" />
|
||||
<timestamp key="myTimestamp" timeReference="contextBirth"
|
||||
datePattern="HH-mm-ss" />
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<layout class="ch.qos.logback.classic.PatternLayout">
|
||||
<Pattern>[%p] %d [%.12t] %c \(%M\) - %msg%n</Pattern>
|
||||
</layout>
|
||||
</appender>
|
||||
<root>
|
||||
<level value="INFO" />
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
Loading…
Reference in New Issue