Skip to content

Commit

Permalink
openvidu-test-e2e: enable tests (one-to-one audio and video only, mas…
Browse files Browse the repository at this point in the history
…sive room)
  • Loading branch information
pabloFuente committed Sep 28, 2024
1 parent 28a0574 commit 71598c2
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.awt.Point;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -164,83 +163,23 @@ public void stopVideoTracksOfVideoElement(WebElement videoElement, String parent
((JavascriptExecutor) driver).executeScript(script);
}

public boolean assertMediaTracks(WebElement videoElement, boolean audioTransmission, boolean videoTransmission,
String parentSelector) {
return this.assertMediaTracks(Collections.singleton(videoElement), audioTransmission, videoTransmission,
parentSelector);
}

public boolean assertMediaTracks(Iterable<WebElement> mediaElements, boolean audioTransmission,
boolean videoTransmission) {
boolean success = true;
for (WebElement mediaElement : mediaElements) {
if (!waitUntilSrcObjectDefined(mediaElement, "", 5000)) {
System.err.println("srcObject of HTMLVideoElement was not defined!");
return false;
}
success = success && (audioTransmission == this.hasAudioTracks(mediaElement, ""))
&& (videoTransmission == this.hasVideoTracks(mediaElement, ""));
if (!success)
break;
}
return success;
}

public boolean assertMediaTracks(Iterable<WebElement> videoElements, boolean audioTransmission,
boolean videoTransmission, String parentSelector) {
boolean success = true;
for (WebElement video : videoElements) {
if (!waitUntilSrcObjectDefined(video, "", 5000)) {
System.err.println("srcObject of HTMLVideoElement was not defined!");
return false;
}
success = success && (audioTransmission == this.hasAudioTracks(video, parentSelector))
&& (videoTransmission == this.hasVideoTracks(video, parentSelector));
if (!success)
break;
public boolean assertAllElementsHaveTracks(String querySelector, boolean hasAudio, boolean hasVideo) {
String calculateReturnValue = "returnValue && ";
if (hasAudio) {
calculateReturnValue += "el.srcObject.getAudioTracks().length === 1 && el.srcObject.getAudioTracks()[0].enabled";
} else {
calculateReturnValue += "el.srcObject.getAudioTracks().length === 0";
}
return success;
}

private boolean hasAudioTracks(WebElement mediaElement, String parentSelector) {
String script = "return ((document.querySelector('" + parentSelector + (parentSelector.isEmpty() ? "" : " ")
+ "#" + mediaElement.getAttribute("id") + "').srcObject.getAudioTracks().length === 1)"
+ " && (document.querySelector('" + parentSelector + (parentSelector.isEmpty() ? "" : " ") + "#"
+ mediaElement.getAttribute("id") + "').srcObject.getAudioTracks()[0].enabled))";
boolean audioTracks = (boolean) ((JavascriptExecutor) driver).executeScript(script);
return audioTracks;
}

private boolean hasVideoTracks(WebElement mediaElement, String parentSelector) {
String script = "return ((document.querySelector('" + parentSelector + (parentSelector.isEmpty() ? "" : " ")
+ "#" + mediaElement.getAttribute("id") + "').srcObject.getVideoTracks().length === 1)"
+ " && (document.querySelector('" + parentSelector + (parentSelector.isEmpty() ? "" : " ") + "#"
+ mediaElement.getAttribute("id") + "').srcObject.getVideoTracks()[0].enabled))";
boolean videoTracks = (boolean) ((JavascriptExecutor) driver).executeScript(script);
return videoTracks;
}

private boolean waitUntilSrcObjectDefined(WebElement videoElement, String parentSelector, int maxMsWait) {
final int sleepInterval = 50;
int maxIterations = maxMsWait / sleepInterval;
int counter = 0;
boolean defined = srcObjectDefined(videoElement, parentSelector);
while (!defined && counter < maxIterations) {
try {
Thread.sleep(sleepInterval);
} catch (InterruptedException e) {
}
defined = srcObjectDefined(videoElement, parentSelector);
counter++;
calculateReturnValue += " && ";
if (hasVideo) {
calculateReturnValue += "el.srcObject.getVideoTracks().length === 1 && el.srcObject.getVideoTracks()[0].enabled";
} else {
calculateReturnValue += "el.srcObject.getVideoTracks().length === 0";
}
return defined;
}

private boolean srcObjectDefined(WebElement videoElement, String parentSelector) {
String script = "return (!!(document.querySelector('" + parentSelector + (parentSelector.isEmpty() ? "" : " ")
+ "#" + videoElement.getAttribute("id") + "').srcObject))";
boolean defined = (boolean) ((JavascriptExecutor) driver).executeScript(script);
return defined;
String script = "var returnValue = true; document.querySelectorAll('" + querySelector
+ "').forEach(el => { returnValue = " + calculateReturnValue + " }); return returnValue;";
boolean tracks = (boolean) ((JavascriptExecutor) driver).executeScript(script);
return tracks;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public class OpenViduTestE2e {

protected static String MEDIA_SERVER_IMAGE = "livekit-server:latest";

protected static String LIVEKIT_API_KEY = "key1";
protected static String LIVEKIT_API_SECRET = "abcdefghijklmnopqrstuvwxyz123456";
protected static String LIVEKIT_URL = "wss://localhost:1880/";
protected static String LIVEKIT_API_KEY = "devkey";
protected static String LIVEKIT_API_SECRET = "secret";
protected static String LIVEKIT_URL = "ws://localhost:7880/";
protected static String APP_URL = "https://localhost:4200/";

protected static String OPENVIDU_PRO_LICENSE = "not_valid";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -102,20 +101,15 @@ private void oneToOneAux(OpenViduTestappUser user) throws Exception {
Assertions.assertEquals(4, numberOfVideos, "Wrong number of videos");
Assertions.assertEquals(4, numberOfAudios, "Wrong number of audios");

Assertions.assertTrue(user.getBrowserUser()
.assertMediaTracks(user.getDriver().findElements(By.tagName("video")), false, true),
Assertions.assertTrue(user.getBrowserUser().assertAllElementsHaveTracks("video", false, true),
"HTMLVideoElements were expected to have only one video track");
Assertions
.assertTrue(
user.getBrowserUser().assertMediaTracks(
user.getDriver().findElements(By.cssSelector("audio.remote")), true, false),
"HTMLAudioElements were expected to have only one audio track");
Assertions.assertTrue(user.getBrowserUser().assertAllElementsHaveTracks("audio.remote", true, false),
"HTMLAudioElements were expected to have only one audio track");
gracefullyLeaveParticipants(user, 2);
}

@Test
@DisplayName("One2One only audio")
@Disabled
void oneToOneOnlyAudioSession() throws Exception {

OpenViduTestappUser user = setupBrowserAndConnectToOpenViduTestapp("chrome");
Expand All @@ -124,26 +118,33 @@ void oneToOneOnlyAudioSession() throws Exception {

user.getDriver().findElement(By.id("one2one-btn")).click();

user.getDriver().findElements(By.className("send-video-checkbox")).forEach(el -> el.click());
for (int n = 0; n < 2; n++) {
user.getDriver().findElement(By.id("room-options-btn-" + n)).click();
Thread.sleep(300);
user.getDriver().findElement(By.id("video-capture-false")).click();
user.getDriver().findElement(By.id("close-dialog-btn")).click();
Thread.sleep(300);
}

user.getDriver().findElements(By.className("connect-btn")).forEach(el -> el.sendKeys(Keys.ENTER));

user.getEventManager().waitUntilEventReaches("connectionCreated", "RoomEvent", 4);
user.getEventManager().waitUntilEventReaches("accessAllowed", "RoomEvent", 2);
user.getEventManager().waitUntilEventReaches("streamCreated", "RoomEvent", 4);
user.getEventManager().waitUntilEventReaches("streamPlaying", "RoomEvent", 4);
user.getEventManager().waitUntilEventReaches("connected", "RoomEvent", 2);
user.getEventManager().waitUntilEventReaches("localTrackPublished", "RoomEvent", 2);
user.getEventManager().waitUntilEventReaches("trackSubscribed", "RoomEvent", 2);

final int numberOfVideos = user.getDriver().findElements(By.tagName("video")).size();
Assertions.assertEquals(4, numberOfVideos, "Wrong number of videos");
Assertions.assertTrue(user.getBrowserUser()
.assertMediaTracks(user.getDriver().findElements(By.tagName("video")), true, false),
"Videos were expected to only have audio tracks");
Assertions.assertEquals(0, numberOfVideos, "Wrong number of videos");
final int numberOfAudios = user.getDriver().findElements(By.tagName("audio")).size();
Assertions.assertEquals(4, numberOfAudios, "Wrong number of audios");

Assertions.assertTrue(user.getBrowserUser().assertAllElementsHaveTracks("audio.remote", true, false),
"HTMLAudioElements were expected to have only one audio track");

gracefullyLeaveParticipants(user, 2);
}

@Test
@DisplayName("One2One only video")
@Disabled
void oneToOneOnlyVideoSession() throws Exception {

OpenViduTestappUser user = setupBrowserAndConnectToOpenViduTestapp("chrome");
Expand All @@ -152,19 +153,27 @@ void oneToOneOnlyVideoSession() throws Exception {

user.getDriver().findElement(By.id("one2one-btn")).click();

user.getDriver().findElements(By.className("send-audio-checkbox")).forEach(el -> el.click());
for (int n = 0; n < 2; n++) {
user.getDriver().findElement(By.id("room-options-btn-" + n)).click();
Thread.sleep(300);
user.getDriver().findElement(By.id("audio-capture-false")).click();
user.getDriver().findElement(By.id("close-dialog-btn")).click();
Thread.sleep(300);
}

user.getDriver().findElements(By.className("connect-btn")).forEach(el -> el.sendKeys(Keys.ENTER));

user.getEventManager().waitUntilEventReaches("connectionCreated", "RoomEvent", 4);
user.getEventManager().waitUntilEventReaches("accessAllowed", "RoomEvent", 2);
user.getEventManager().waitUntilEventReaches("streamCreated", "RoomEvent", 4);
user.getEventManager().waitUntilEventReaches("streamPlaying", "RoomEvent", 4);
user.getEventManager().waitUntilEventReaches("connected", "RoomEvent", 2);
user.getEventManager().waitUntilEventReaches("localTrackPublished", "RoomEvent", 2);
user.getEventManager().waitUntilEventReaches("trackSubscribed", "RoomEvent", 2);

final int numberOfAudios = user.getDriver().findElements(By.tagName("audio")).size();
Assertions.assertEquals(0, numberOfAudios, "Wrong number of audios");
final int numberOfVideos = user.getDriver().findElements(By.tagName("video")).size();
Assertions.assertEquals(4, numberOfVideos, "Wrong number of videos");
Assertions.assertTrue(user.getBrowserUser()
.assertMediaTracks(user.getDriver().findElements(By.tagName("video")), false, true),
"Videos were expected to only have video tracks");

Assertions.assertTrue(user.getBrowserUser().assertAllElementsHaveTracks("video", false, true),
"HTMLVideoElements were expected to have only one audio track");

gracefullyLeaveParticipants(user, 2);
}
Expand All @@ -177,34 +186,33 @@ void oneToManyVideoAudioSession() throws Exception {

log.info("One2Many [Video + Audio]");

final int SUBSCRIBERS = 7;
final int USERS = SUBSCRIBERS + 1;

WebElement one2ManyInput = user.getDriver().findElement(By.id("one2many-input"));
one2ManyInput.clear();
one2ManyInput.sendKeys("3");
one2ManyInput.sendKeys(Integer.toString(SUBSCRIBERS));
user.getDriver().findElement(By.id("auto-join-checkbox")).click();
user.getDriver().findElement(By.id("one2many-btn")).click();

user.getEventManager().waitUntilEventReaches("signalConnected", "RoomEvent", 4);
user.getEventManager().waitUntilEventReaches("connected", "RoomEvent", 4);
user.getEventManager().waitUntilEventReaches("signalConnected", "RoomEvent", USERS);
user.getEventManager().waitUntilEventReaches("connected", "RoomEvent", USERS);
user.getEventManager().waitUntilEventReaches("localTrackPublished", "RoomEvent", 2);
user.getEventManager().waitUntilEventReaches("trackSubscribed", "RoomEvent", 6);
user.getEventManager().waitUntilEventReaches("trackSubscribed", "RoomEvent", (SUBSCRIBERS) * 2);

user.getWaiter().until(ExpectedConditions.numberOfElementsToBe(By.tagName("video"), 4));
user.getWaiter().until(ExpectedConditions.numberOfElementsToBe(By.tagName("audio"), 4));
user.getWaiter().until(ExpectedConditions.numberOfElementsToBe(By.tagName("video"), USERS));
user.getWaiter().until(ExpectedConditions.numberOfElementsToBe(By.tagName("audio"), USERS));
final int numberOfVideos = user.getDriver().findElements(By.tagName("video")).size();
final int numberOfAudios = user.getDriver().findElements(By.tagName("audio")).size();
Assertions.assertEquals(4, numberOfVideos, "Wrong number of videos");
Assertions.assertEquals(4, numberOfAudios, "Wrong number of audios");
Assertions.assertEquals(USERS, numberOfVideos, "Wrong number of videos");
Assertions.assertEquals(USERS, numberOfAudios, "Wrong number of audios");

Assertions.assertTrue(user.getBrowserUser()
.assertMediaTracks(user.getDriver().findElements(By.tagName("video")), false, true),
Assertions.assertTrue(user.getBrowserUser().assertAllElementsHaveTracks("video", false, true),
"HTMLVideoElements were expected to have only one video track");
Assertions
.assertTrue(
user.getBrowserUser().assertMediaTracks(
user.getDriver().findElements(By.cssSelector("audio.remote")), true, false),
"HTMLAudioElements were expected to have only one audio track");
Assertions.assertTrue(user.getBrowserUser().assertAllElementsHaveTracks("audio.remote", true, false),
"HTMLAudioElements were expected to have only one audio track");

gracefullyLeaveParticipants(user, 4);
gracefullyLeaveParticipants(user, USERS);
}

@Test
Expand Down Expand Up @@ -234,46 +242,48 @@ void manyToManyVideoAudioSession() throws Exception {
Assertions.assertEquals(16, numberOfVideos, "Wrong number of videos");
Assertions.assertEquals(16, numberOfAudios, "Wrong number of audios");

Assertions.assertTrue(user.getBrowserUser()
.assertMediaTracks(user.getDriver().findElements(By.tagName("video")), false, true),
Assertions.assertTrue(user.getBrowserUser().assertAllElementsHaveTracks("video", false, true),
"HTMLVideoElements were expected to have only one video track");
Assertions
.assertTrue(
user.getBrowserUser().assertMediaTracks(
user.getDriver().findElements(By.cssSelector("audio.remote")), true, false),
"HTMLAudioElements were expected to have only one audio track");
Assertions.assertTrue(user.getBrowserUser().assertAllElementsHaveTracks("audio.remote", true, false),
"HTMLAudioElements were expected to have only one audio track");

gracefullyLeaveParticipants(user, 4);
}

@Test
@DisplayName("Massive session")
@Disabled
void massiveSessionTest() throws Exception {

OpenViduTestappUser user = setupBrowserAndConnectToOpenViduTestapp("chrome");

log.info("Massive session");

final Integer NUMBER_OF_USERS = 7;
final Integer NUMBER_OF_USERS = 8;

user.getDriver().findElement(By.id("toolbar-scenarios")).sendKeys(Keys.ENTER);

WebElement one2ManyInput = user.getDriver().findElement(By.id("one2many-input"));
one2ManyInput.clear();
one2ManyInput.sendKeys(NUMBER_OF_USERS.toString());
WebElement many2ManyInput = user.getDriver().findElement(By.id("m2m-input"));
many2ManyInput.clear();
many2ManyInput.sendKeys(NUMBER_OF_USERS.toString());

user.getDriver().findElement(By.id("one2many-btn")).click();
user.getDriver().findElement(By.id("m2m-btn")).click();

user.getEventManager().waitUntilEventReaches("signalConnected", "RoomEvent", NUMBER_OF_USERS);
user.getEventManager().waitUntilEventReaches("connected", "RoomEvent", NUMBER_OF_USERS);
user.getEventManager().waitUntilEventReaches("localTrackPublished", "RoomEvent", NUMBER_OF_USERS * 2);
user.getEventManager().waitUntilEventReaches("trackPublished", "RoomEvent",
(NUMBER_OF_USERS) * (NUMBER_OF_USERS - 1) * 2);
user.getEventManager().waitUntilEventReaches("trackSubscribed", "RoomEvent",
(NUMBER_OF_USERS) * (NUMBER_OF_USERS - 1) * 2);

user.getWaiter()
.until(ExpectedConditions.numberOfElementsToBe(By.tagName("video"), NUMBER_OF_USERS * NUMBER_OF_USERS));
Assertions.assertTrue(user.getBrowserUser().assertAllElementsHaveTracks("video", true, true),
"HTMLVideoElements were expected to have a video track and an audio track attached");

user.getEventManager().waitUntilEventReaches("streamCreated", "RoomEvent", NUMBER_OF_USERS * NUMBER_OF_USERS);
user.getEventManager().waitUntilEventReaches("streamPlaying", "RoomEvent", NUMBER_OF_USERS * NUMBER_OF_USERS);

this.stopMediaServer();
user.getDriver().findElement(By.id("finish-btn")).click();

user.getEventManager().waitUntilEventReaches("sessionDisconnected", "RoomEvent", NUMBER_OF_USERS);
user.getEventManager().waitUntilEventReaches("disconnected", "RoomEvent", NUMBER_OF_USERS);
}

@Test
Expand Down Expand Up @@ -315,14 +325,9 @@ public void uncaughtException(Thread th, Throwable ex) {
Assertions.assertEquals(3, numberOfVideos, "Wrong number of videos");
Assertions.assertEquals(3, numberOfAudios, "Wrong number of audios");

Assertions
.assertTrue(
user.getBrowserUser().assertMediaTracks(
user.getDriver().findElements(By.tagName("video")), false, true),
"HTMLVideoElements were expected to have only one video track");
Assertions.assertTrue(
user.getBrowserUser().assertMediaTracks(
user.getDriver().findElements(By.cssSelector("audio.remote")), true, false),
Assertions.assertTrue(user.getBrowserUser().assertAllElementsHaveTracks("video", false, true),
"HTMLVideoElements were expected to have only one video track");
Assertions.assertTrue(user.getBrowserUser().assertAllElementsHaveTracks("audio.remote", true, false),
"HTMLAudioElements were expected to have only one audio track");

latch.countDown();
Expand Down
Loading

0 comments on commit 71598c2

Please sign in to comment.