openvidu-test-e2e: testcontainers + edge test

pull/664/head
pabloFuente 2021-11-04 13:17:58 +01:00
parent e32330ad95
commit dcdcbd1055
15 changed files with 540 additions and 437 deletions

View File

@ -56,11 +56,11 @@ public class BrowserUser {
} }
protected void newWaiter(int timeOfWait) { protected void newWaiter(int timeOfWait) {
this.waiter = new WebDriverWait(this.driver, timeOfWait); this.waiter = new WebDriverWait(this.driver, Duration.ofSeconds(timeOfWait));
} }
protected void configureDriver() { protected void configureDriver() {
this.waiter = new WebDriverWait(this.driver, this.timeOfWaitInSeconds); this.waiter = new WebDriverWait(this.driver, Duration.ofSeconds(timeOfWaitInSeconds));
this.driver.manage().window().setSize(new org.openqa.selenium.Dimension(1920, 1080)); this.driver.manage().window().setSize(new org.openqa.selenium.Dimension(1920, 1080));
} }

View File

@ -1,68 +0,0 @@
/*
* (C) Copyright 2017-2020 OpenVidu (https://openvidu.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package io.openvidu.test.browsers;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class ChromeAndroidUser extends BrowserUser {
public ChromeAndroidUser(String userName, int timeOfWaitInSeconds) {
super(userName, timeOfWaitInSeconds);
Map<String, String> mobileEmulation = new HashMap<>();
mobileEmulation.put("deviceName", "Pixel 2");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setAcceptInsecureCerts(true);
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
// This flag avoids to grant the user media
chromeOptions.addArguments("--use-fake-ui-for-media-stream");
// This flag fakes user media with synthetic video
chromeOptions.addArguments("--use-fake-device-for-media-stream");
String REMOTE_URL = System.getProperty("REMOTE_URL_CHROME");
if (REMOTE_URL != null) {
log.info("Using URL {} to connect to remote web driver", REMOTE_URL);
try {
this.driver = new RemoteWebDriver(new URL(REMOTE_URL), capabilities);
} catch (MalformedURLException e) {
e.printStackTrace();
}
} else {
log.info("Using local web driver");
this.driver = new ChromeDriver(capabilities);
}
this.driver.manage().timeouts().setScriptTimeout(this.timeOfWaitInSeconds, TimeUnit.SECONDS);
this.configureDriver();
}
}

View File

@ -21,9 +21,9 @@ import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.time.Duration;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.UnexpectedAlertBehaviour; import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeDriver;
@ -71,7 +71,7 @@ public class ChromeUser extends BrowserUser {
this.driver = new ChromeDriver(options); this.driver = new ChromeDriver(options);
} }
this.driver.manage().timeouts().setScriptTimeout(this.timeOfWaitInSeconds, TimeUnit.SECONDS); this.driver.manage().timeouts().scriptTimeout(Duration.ofSeconds(timeOfWaitInSeconds));
this.configureDriver(); this.configureDriver();
} }

View File

@ -0,0 +1,43 @@
package io.openvidu.test.browsers;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.RemoteWebDriver;
public class EdgeUser extends BrowserUser {
public EdgeUser(String userName, int timeOfWaitInSeconds) {
super(userName, timeOfWaitInSeconds);
EdgeOptions options = new EdgeOptions();
options.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE);
options.setAcceptInsecureCerts(true);
options.addArguments("allow-file-access-from-files");
options.addArguments("use-fake-device-for-media-stream");
options.addArguments("use-fake-ui-for-media-stream");
String REMOTE_URL = System.getProperty("REMOTE_URL_EDGE");
if (REMOTE_URL != null) {
log.info("Using URL {} to connect to remote web driver", REMOTE_URL);
try {
this.driver = new RemoteWebDriver(new URL(REMOTE_URL), options);
} catch (MalformedURLException e) {
e.printStackTrace();
}
} else {
log.info("Using local web driver");
this.driver = new EdgeDriver(options);
}
this.driver.manage().timeouts().scriptTimeout(Duration.ofSeconds(timeOfWaitInSeconds));
this.configureDriver();
}
}

View File

@ -19,13 +19,13 @@ package io.openvidu.test.browsers;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.time.Duration;
import org.openqa.selenium.UnexpectedAlertBehaviour; import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions; import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile; import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.remote.RemoteWebDriver;
public class FirefoxUser extends BrowserUser { public class FirefoxUser extends BrowserUser {
@ -33,9 +33,14 @@ public class FirefoxUser extends BrowserUser {
public FirefoxUser(String userName, int timeOfWaitInSeconds, boolean disableOpenH264) { public FirefoxUser(String userName, int timeOfWaitInSeconds, boolean disableOpenH264) {
super(userName, timeOfWaitInSeconds); super(userName, timeOfWaitInSeconds);
DesiredCapabilities capabilities = DesiredCapabilities.firefox(); FirefoxOptions options = new FirefoxOptions();
capabilities.setAcceptInsecureCerts(true);
capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE); options.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE);
options.setAcceptInsecureCerts(true);
options.addArguments("allow-file-access-from-files");
options.addArguments("use-fake-device-for-media-stream");
options.addArguments("use-fake-ui-for-media-stream");
FirefoxProfile profile = new FirefoxProfile(); FirefoxProfile profile = new FirefoxProfile();
// This flag avoids granting the access to the camera // This flag avoids granting the access to the camera
@ -47,21 +52,22 @@ public class FirefoxUser extends BrowserUser {
profile.setPreference("media.gmp-gmpopenh264.enabled", false); profile.setPreference("media.gmp-gmpopenh264.enabled", false);
} }
capabilities.setCapability(FirefoxDriver.PROFILE, profile); options.setCapability(FirefoxDriver.Capability.PROFILE, profile);
String REMOTE_URL = System.getProperty("REMOTE_URL_FIREFOX"); String REMOTE_URL = System.getProperty("REMOTE_URL_FIREFOX");
if (REMOTE_URL != null) { if (REMOTE_URL != null) {
log.info("Using URL {} to connect to remote web driver", REMOTE_URL); log.info("Using URL {} to connect to remote web driver", REMOTE_URL);
try { try {
this.driver = new RemoteWebDriver(new URL(REMOTE_URL), capabilities); this.driver = new RemoteWebDriver(new URL(REMOTE_URL), options);
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
e.printStackTrace(); e.printStackTrace();
} }
} else { } else {
log.info("Using local web driver"); log.info("Using local web driver");
this.driver = new FirefoxDriver(new FirefoxOptions(capabilities)); this.driver = new FirefoxDriver(options);
} }
this.driver.manage().timeouts().scriptTimeout(Duration.ofSeconds(timeOfWaitInSeconds));
this.configureDriver(); this.configureDriver();
} }

View File

@ -2,11 +2,12 @@ package io.openvidu.test.browsers;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.concurrent.TimeUnit; import java.time.Duration;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.opera.OperaDriver; import org.openqa.selenium.opera.OperaDriver;
import org.openqa.selenium.opera.OperaOptions; import org.openqa.selenium.opera.OperaOptions;
import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.remote.RemoteWebDriver;
public class OperaUser extends BrowserUser { public class OperaUser extends BrowserUser {
@ -14,16 +15,13 @@ public class OperaUser extends BrowserUser {
public OperaUser(String userName, int timeOfWaitInSeconds) { public OperaUser(String userName, int timeOfWaitInSeconds) {
super(userName, timeOfWaitInSeconds); super(userName, timeOfWaitInSeconds);
DesiredCapabilities capabilities = DesiredCapabilities.operaBlink();
capabilities.setAcceptInsecureCerts(true);
OperaOptions options = new OperaOptions(); OperaOptions options = new OperaOptions();
// This flag avoids to grant the user media
options.addArguments("--use-fake-ui-for-media-stream"); options.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE);
// This flag fakes user media with synthetic video options.setAcceptInsecureCerts(true);
options.addArguments("--use-fake-device-for-media-stream"); options.addArguments("allow-file-access-from-files");
// This flag selects the entire screen as video source when screen sharing options.addArguments("use-fake-device-for-media-stream");
options.addArguments("--auto-select-desktop-capture-source=Entire screen"); options.addArguments("use-fake-ui-for-media-stream");
options.merge(capabilities);
String REMOTE_URL = System.getProperty("REMOTE_URL_OPERA"); String REMOTE_URL = System.getProperty("REMOTE_URL_OPERA");
if (REMOTE_URL != null) { if (REMOTE_URL != null) {
@ -38,7 +36,7 @@ public class OperaUser extends BrowserUser {
this.driver = new OperaDriver(options); this.driver = new OperaDriver(options);
} }
this.driver.manage().timeouts().setScriptTimeout(this.timeOfWaitInSeconds, TimeUnit.SECONDS); this.driver.manage().timeouts().scriptTimeout(Duration.ofSeconds(timeOfWaitInSeconds));
this.configureDriver(); this.configureDriver();
} }

View File

@ -0,0 +1,7 @@
package io.openvidu.test.browsers.utils;
public enum BrowserNames {
CHROME, FIREFOX, OPERA, EDGE
}

View File

@ -113,12 +113,7 @@ node('container') {
'''.stripIndent()) '''.stripIndent())
} }
docker.image('selenium/standalone-chrome:latest').withRun('-p 6666:4444 --name chrome --shm-size=2g -v /opt/openvidu:/opt/openvidu') { a -> // Kurento tests
docker.image('selenium/standalone-firefox:latest').withRun('-p 6667:4444 --name firefox --shm-size=2g') { b ->
docker.image('selenium/standalone-opera:latest').withRun('-p 6668:4444 --name opera --shm-size=2g') { c ->
// -----
// Kurento TESTS
// -----
stage ('Environment Launch Kurento') { stage ('Environment Launch Kurento') {
environmentLaunch('kurento') environmentLaunch('kurento')
} }
@ -142,9 +137,7 @@ node('container') {
environmentStop() environmentStop()
} }
// ---- // Mediasoup tests
// Mediasoup TESTS
// ----
stage ('Environment Launch Mediasoup') { stage ('Environment Launch Mediasoup') {
environmentLaunch('mediasoup') environmentLaunch('mediasoup')
} }
@ -168,9 +161,6 @@ node('container') {
commonFunctions.removeStrandedContainers(false) commonFunctions.removeStrandedContainers(false)
} }
} }
}
}
}
} }
def environmentLaunch(mediaServer) { def environmentLaunch(mediaServer) {

View File

@ -46,6 +46,9 @@ def prepareTestingEnvironment() {
'Pull selenium/standalone-opera': { 'Pull selenium/standalone-opera': {
docker.image('selenium/standalone-opera:latest').pull() docker.image('selenium/standalone-opera:latest').pull()
}, },
'Pull selenium/standalone-edge': {
docker.image('selenium/standalone-edge:latest').pull()
},
'Pull openvidu/mediasoup-controller': { 'Pull openvidu/mediasoup-controller': {
if (env.MEDIASOUP_CONTROLLER_VERSION) { if (env.MEDIASOUP_CONTROLLER_VERSION) {
docker.image("openvidu/mediasoup-controller:${MEDIASOUP_CONTROLLER_VERSION}").pull() docker.image("openvidu/mediasoup-controller:${MEDIASOUP_CONTROLLER_VERSION}").pull()
@ -92,6 +95,7 @@ def removeStrandedContainers(removeTestingContainers) {
declare -a arr=("selenium/standalone-chrome:" declare -a arr=("selenium/standalone-chrome:"
"selenium/standalone-firefox:" "selenium/standalone-firefox:"
"selenium/standalone-opera:" "selenium/standalone-opera:"
"selenium/standalone-edge:"
"openvidu/mediasoup-controller:" "openvidu/mediasoup-controller:"
"openvidu/openvidu-server-pro:" "openvidu/openvidu-server-pro:"
"openvidu/openvidu-redis:" "openvidu/openvidu-redis:"

View File

@ -126,6 +126,12 @@
<version>${version.openvidu.java.client}</version> <version>${version.openvidu.java.client}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>${version.testcontainers}</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -7,16 +7,21 @@ import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
import org.junit.Assert; import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.openqa.selenium.By; import org.openqa.selenium.By;
import org.openqa.selenium.Keys; import org.openqa.selenium.Keys;
@ -27,6 +32,9 @@ import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.ExpectedConditions;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.utility.DockerImageName;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
@ -38,16 +46,31 @@ import io.openvidu.java.client.OpenViduHttpException;
import io.openvidu.java.client.OpenViduJavaClientException; import io.openvidu.java.client.OpenViduJavaClientException;
import io.openvidu.java.client.VideoCodec; import io.openvidu.java.client.VideoCodec;
import io.openvidu.test.browsers.BrowserUser; import io.openvidu.test.browsers.BrowserUser;
import io.openvidu.test.browsers.ChromeAndroidUser;
import io.openvidu.test.browsers.ChromeUser; import io.openvidu.test.browsers.ChromeUser;
import io.openvidu.test.browsers.EdgeUser;
import io.openvidu.test.browsers.FirefoxUser; import io.openvidu.test.browsers.FirefoxUser;
import io.openvidu.test.browsers.OperaUser; import io.openvidu.test.browsers.OperaUser;
import io.openvidu.test.browsers.utils.BrowserNames;
import io.openvidu.test.browsers.utils.CommandLineExecutor; import io.openvidu.test.browsers.utils.CommandLineExecutor;
import io.openvidu.test.browsers.utils.CustomHttpClient; import io.openvidu.test.browsers.utils.CustomHttpClient;
import io.openvidu.test.browsers.utils.RecordingUtils; import io.openvidu.test.browsers.utils.RecordingUtils;
public class AbstractOpenViduTestAppE2eTest { public class AbstractOpenViduTestAppE2eTest {
@ClassRule
public static GenericContainer<?> chrome;
@ClassRule
public static GenericContainer<?> firefox;
@ClassRule
public static GenericContainer<?> opera;
@ClassRule
public static GenericContainer<?> edge;
private Map<BrowserNames, Set<String>> webdriverVersions = new HashMap<>();
// Media server variables // Media server variables
final protected static String KURENTO_IMAGE = "kurento/kurento-media-server"; final protected static String KURENTO_IMAGE = "kurento/kurento-media-server";
final protected static String MEDIASOUP_IMAGE = "openvidu/mediasoup-controller"; final protected static String MEDIASOUP_IMAGE = "openvidu/mediasoup-controller";
@ -66,6 +89,16 @@ public class AbstractOpenViduTestAppE2eTest {
protected static String OPENVIDU_PRO_LICENSE = "not_valid"; protected static String OPENVIDU_PRO_LICENSE = "not_valid";
protected static String OPENVIDU_PRO_LICENSE_API = "not_valid"; protected static String OPENVIDU_PRO_LICENSE_API = "not_valid";
protected static String EXTERNAL_CUSTOM_LAYOUT_PARAMS = "sessionId,CUSTOM_LAYOUT_SESSION,secret,MY_SECRET"; protected static String EXTERNAL_CUSTOM_LAYOUT_PARAMS = "sessionId,CUSTOM_LAYOUT_SESSION,secret,MY_SECRET";
// https://hub.docker.com/r/selenium/standalone-chrome/tags
protected static String CHROME_VERSION = "latest";
// https://hub.docker.com/r/selenium/standalone-firefox/tags
protected static String FIREFOX_VERSION = "latest";
// https://hub.docker.com/r/selenium/standalone-opera/tags
protected static String OPERA_VERSION = "latest";
// https://hub.docker.com/r/selenium/standalone-edge/tags
protected static String EDGE_VERSION = "latest";
protected static Exception ex = null; protected static Exception ex = null;
protected final Object lock = new Object(); protected final Object lock = new Object();
@ -73,8 +106,7 @@ public class AbstractOpenViduTestAppE2eTest {
protected static final CommandLineExecutor commandLine = new CommandLineExecutor(); protected static final CommandLineExecutor commandLine = new CommandLineExecutor();
protected static final String RECORDING_IMAGE = "openvidu/openvidu-recording"; protected static final String RECORDING_IMAGE = "openvidu/openvidu-recording";
protected MyUser user; private Collection<MyUser> users = new HashSet<>();
protected Collection<MyUser> otherUsers = new ArrayList<>();
protected volatile static boolean isRecordingTest; protected volatile static boolean isRecordingTest;
protected volatile static boolean isKurentoRestartTest; protected volatile static boolean isKurentoRestartTest;
@ -96,11 +128,41 @@ public class AbstractOpenViduTestAppE2eTest {
} }
} }
protected static void setupBrowserDrivers() { @SuppressWarnings("resource")
protected static void prepareBrowsers() {
if (isRemote(BrowserNames.CHROME)) {
chrome = new GenericContainer<>(DockerImageName.parse("selenium/standalone-chrome:" + CHROME_VERSION))
.withSharedMemorySize(2147483648L).withFileSystemBind("/opt/openvidu", "/opt/openvidu");
chrome.setPortBindings(Arrays.asList("6666:4444"));
chrome.withExposedPorts(4444);
} else {
WebDriverManager.chromedriver().setup(); WebDriverManager.chromedriver().setup();
}
if (isRemote(BrowserNames.FIREFOX)) {
firefox = new GenericContainer<>(DockerImageName.parse("selenium/standalone-firefox:" + FIREFOX_VERSION))
.withSharedMemorySize(2147483648L).withFileSystemBind("/opt/openvidu", "/opt/openvidu");
firefox.setPortBindings(Arrays.asList("6667:4444"));
firefox.withExposedPorts(4444);
} else {
WebDriverManager.firefoxdriver().setup(); WebDriverManager.firefoxdriver().setup();
}
if (isRemote(BrowserNames.OPERA)) {
opera = new GenericContainer<>(DockerImageName.parse("selenium/standalone-opera:" + OPERA_VERSION))
.withSharedMemorySize(2147483648L).withFileSystemBind("/opt/openvidu", "/opt/openvidu");
opera.setPortBindings(Arrays.asList("6668:4444"));
opera.withExposedPorts(4444);
} else {
WebDriverManager.operadriver().setup(); WebDriverManager.operadriver().setup();
} }
if (isRemote(BrowserNames.EDGE)) {
edge = new GenericContainer<>(DockerImageName.parse("selenium/standalone-edge:" + EDGE_VERSION))
.withSharedMemorySize(2147483648L).withFileSystemBind("/opt/openvidu", "/opt/openvidu");
edge.setPortBindings(Arrays.asList("6669:4444"));
edge.withExposedPorts(4444);
} else {
WebDriverManager.edgedriver().setup();
}
}
protected static void cleanFoldersAndSetUpOpenViduJavaClient() { protected static void cleanFoldersAndSetUpOpenViduJavaClient() {
try { try {
@ -179,39 +241,64 @@ public class AbstractOpenViduTestAppE2eTest {
if (openviduProLicenseApi != null) { if (openviduProLicenseApi != null) {
OPENVIDU_PRO_LICENSE_API = openviduProLicenseApi; OPENVIDU_PRO_LICENSE_API = openviduProLicenseApi;
} }
String chromeVersion = System.getProperty("CHROME_VERSION");
if (chromeVersion != null) {
CHROME_VERSION = chromeVersion;
}
String firefoxVersion = System.getProperty("FIREFOX_VERSION");
if (firefoxVersion != null) {
FIREFOX_VERSION = firefoxVersion;
}
String operaVersion = System.getProperty("OPERA_VERSION");
if (operaVersion != null) {
OPERA_VERSION = operaVersion;
}
String edgeVersion = System.getProperty("EDGE_VERSION");
if (edgeVersion != null) {
EDGE_VERSION = edgeVersion;
}
} }
protected void setupBrowser(String browser) { protected MyUser setupBrowser(String browser) {
BrowserUser browserUser; BrowserUser browserUser;
switch (browser) { switch (browser) {
case "chrome": case "chrome":
setupBrowserAux(BrowserNames.CHROME, CHROME_VERSION, chrome, WebDriverManager.chromedriver(), false);
browserUser = new ChromeUser("TestUser", 50, false); browserUser = new ChromeUser("TestUser", 50, false);
break; break;
case "firefox": case "firefox":
setupBrowserAux(BrowserNames.FIREFOX, FIREFOX_VERSION, firefox, WebDriverManager.firefoxdriver(), false);
browserUser = new FirefoxUser("TestUser", 50, false); browserUser = new FirefoxUser("TestUser", 50, false);
break; break;
case "firefoxDisabledOpenH264": case "firefoxDisabledOpenH264":
setupBrowserAux(BrowserNames.FIREFOX, FIREFOX_VERSION, firefox, WebDriverManager.firefoxdriver(), false);
browserUser = new FirefoxUser("TestUser", 50, true); browserUser = new FirefoxUser("TestUser", 50, true);
break; break;
case "opera": case "opera":
setupBrowserAux(BrowserNames.OPERA, OPERA_VERSION, opera, WebDriverManager.operadriver(), false);
browserUser = new OperaUser("TestUser", 50); browserUser = new OperaUser("TestUser", 50);
break; break;
case "chromeAndroid": case "edge":
browserUser = new ChromeAndroidUser("TestUser", 50); setupBrowserAux(BrowserNames.EDGE, EDGE_VERSION, edge, WebDriverManager.edgedriver(), false);
browserUser = new EdgeUser("TestUser", 50);
break; break;
case "chromeAlternateScreenShare": case "chromeAlternateScreenShare":
setupBrowserAux(BrowserNames.CHROME, CHROME_VERSION, chrome, WebDriverManager.chromedriver(), false);
browserUser = new ChromeUser("TestUser", 50, "OpenVidu TestApp", false); browserUser = new ChromeUser("TestUser", 50, "OpenVidu TestApp", false);
break; break;
case "chromeAsRoot": case "chromeAsRoot":
setupBrowserAux(BrowserNames.CHROME, CHROME_VERSION, chrome, WebDriverManager.chromedriver(), false);
browserUser = new ChromeUser("TestUser", 50, true); browserUser = new ChromeUser("TestUser", 50, true);
break; break;
default: default:
setupBrowserAux(BrowserNames.CHROME, CHROME_VERSION, chrome, WebDriverManager.chromedriver(), false);
browserUser = new ChromeUser("TestUser", 50, false); browserUser = new ChromeUser("TestUser", 50, false);
} }
this.user = new MyUser(browserUser); MyUser user = new MyUser(browserUser);
user.getDriver().get(APP_URL); user.getDriver().get(APP_URL);
@ -223,10 +310,67 @@ public class AbstractOpenViduTestAppE2eTest {
secretInput.sendKeys(OPENVIDU_SECRET); secretInput.sendKeys(OPENVIDU_SECRET);
user.getEventManager().startPolling(); user.getEventManager().startPolling();
this.users.add(user);
return user;
} }
protected void setupChromeWithFakeVideo(Path videoFileLocation) { private void setupBrowserAux(BrowserNames browser, String version, GenericContainer<?> container,
this.user = new MyUser(new ChromeUser("TestUser", 50, videoFileLocation)); WebDriverManager webDriverManager, boolean forceRestart) {
if (isRemote(browser)) {
if (forceRestart && container.isRunning()) {
container.stop();
}
if (!container.isRunning()) {
container.start();
container.waitingFor(Wait.forHttp("/wd/hub/status").forStatusCode(200));
}
if (webdriverVersions.containsKey(browser)) {
// This browser has already been used
if (!webdriverVersions.get(browser).contains(version)) {
// This browser version has not been used yet
webdriverVersions.get(browser).add(version);
if ("latest".equals(version)) {
webDriverManager.setup();
} else {
webDriverManager.browserVersion(simplifiedBrowserVersion(version)).setup();
}
}
} else {
// This browser has not been used yet
Set<String> versions = new HashSet<>();
versions.add(version);
webdriverVersions.put(browser, versions);
}
}
}
private static boolean isRemote(BrowserNames browser) {
String remoteUrl = null;
switch (browser) {
case CHROME:
remoteUrl = System.getProperty("REMOTE_URL_CHROME");
break;
case FIREFOX:
remoteUrl = System.getProperty("REMOTE_URL_FIREFOX");
break;
case OPERA:
remoteUrl = System.getProperty("REMOTE_URL_OPERA");
break;
case EDGE:
remoteUrl = System.getProperty("REMOTE_URL_EDGE");
break;
}
return remoteUrl != null;
}
protected MyUser setupChromeWithFakeVideo(String absolutePathToVideoFile) {
if (isRemote(BrowserNames.CHROME)) {
setupBrowserAux(BrowserNames.CHROME, CHROME_VERSION, chrome, WebDriverManager.chromedriver(), true);
}
MyUser user = new MyUser(new ChromeUser("TestUser", 50, Paths.get(absolutePathToVideoFile)));
user.getDriver().get(APP_URL); user.getDriver().get(APP_URL);
WebElement urlInput = user.getDriver().findElement(By.id("openvidu-url")); WebElement urlInput = user.getDriver().findElement(By.id("openvidu-url"));
urlInput.clear(); urlInput.clear();
@ -235,6 +379,8 @@ public class AbstractOpenViduTestAppE2eTest {
secretInput.clear(); secretInput.clear();
secretInput.sendKeys(OPENVIDU_SECRET); secretInput.sendKeys(OPENVIDU_SECRET);
user.getEventManager().startPolling(); user.getEventManager().startPolling();
this.users.add(user);
return user;
} }
protected static void getDefaultTranscodingValues() throws Exception { protected static void getDefaultTranscodingValues() throws Exception {
@ -246,15 +392,6 @@ public class AbstractOpenViduTestAppE2eTest {
@AfterEach @AfterEach
protected void dispose() { protected void dispose() {
if (user != null) {
user.dispose();
}
Iterator<MyUser> it = otherUsers.iterator();
while (it.hasNext()) {
MyUser other = it.next();
other.dispose();
it.remove();
}
this.closeAllSessions(OV); this.closeAllSessions(OV);
if (isRecordingTest) { if (isRecordingTest) {
deleteAllRecordings(OV); deleteAllRecordings(OV);
@ -265,6 +402,24 @@ public class AbstractOpenViduTestAppE2eTest {
this.startMediaServer(true); this.startMediaServer(true);
isKurentoRestartTest = false; isKurentoRestartTest = false;
} }
Iterator<MyUser> it = users.iterator();
while (it.hasNext()) {
MyUser u = it.next();
u.dispose();
it.remove();
}
if (chrome.isRunning()) {
chrome.stop();
}
if (firefox.isRunning()) {
firefox.stop();
}
if (opera.isRunning()) {
opera.stop();
}
if (edge.isRunning()) {
edge.stop();
}
OV = new OpenVidu(OPENVIDU_URL, OPENVIDU_SECRET); OV = new OpenVidu(OPENVIDU_URL, OPENVIDU_SECRET);
} }
@ -305,7 +460,7 @@ public class AbstractOpenViduTestAppE2eTest {
} }
} }
protected void listEmptyRecordings() { protected void listEmptyRecordings(MyUser user) {
// List existing recordings (empty) // List existing recordings (empty)
user.getDriver().findElement(By.id("list-recording-btn")).click(); user.getDriver().findElement(By.id("list-recording-btn")).click();
user.getWaiter() user.getWaiter()
@ -322,7 +477,7 @@ public class AbstractOpenViduTestAppE2eTest {
}; };
} }
protected void gracefullyLeaveParticipants(int numberOfParticipants) throws Exception { protected void gracefullyLeaveParticipants(MyUser user, int numberOfParticipants) throws Exception {
int accumulatedConnectionDestroyed = 0; int accumulatedConnectionDestroyed = 0;
for (int j = 1; j <= numberOfParticipants; j++) { for (int j = 1; j <= numberOfParticipants; j++) {
user.getDriver().findElement(By.id("remove-user-btn")).sendKeys(Keys.ENTER); user.getDriver().findElement(By.id("remove-user-btn")).sendKeys(Keys.ENTER);
@ -471,4 +626,11 @@ public class AbstractOpenViduTestAppE2eTest {
} }
} }
private static String simplifiedBrowserVersion(String version) {
String[] v = version.split("\\.");
String firstNumber = v[0].split("-")[0];
log.info("Using version for webdriver {}", firstNumber);
return firstNumber;
}
} }

View File

@ -128,7 +128,6 @@ public class OpenViduEventManager {
try { try {
Thread.sleep(25); Thread.sleep(25);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace();
} }
} }
log.info("Polling thread is now interrupted!"); log.info("Polling thread is now interrupted!");
@ -171,9 +170,11 @@ public class OpenViduEventManager {
this.setCountDown(eventName, eventSignal); this.setCountDown(eventName, eventSignal);
try { try {
if (!eventSignal.await(secondsOfWait * 1000, TimeUnit.MILLISECONDS)) { if (!eventSignal.await(secondsOfWait * 1000, TimeUnit.MILLISECONDS)) {
if (printTimeoutError) {
String screenshot = "data:image/png;base64," + ((TakesScreenshot) driver).getScreenshotAs(BASE64); String screenshot = "data:image/png;base64," + ((TakesScreenshot) driver).getScreenshotAs(BASE64);
System.out.println("TIMEOUT SCREENSHOT"); System.out.println("TIMEOUT SCREENSHOT");
System.out.println(screenshot); System.out.println(screenshot);
}
throw (new TimeoutException()); throw (new TimeoutException());
} }
} catch (InterruptedException | TimeoutException e) { } catch (InterruptedException | TimeoutException e) {

View File

@ -54,7 +54,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
protected static void setupAll() { protected static void setupAll() {
checkFfmpegInstallation(); checkFfmpegInstallation();
loadEnvironmentVariables(); loadEnvironmentVariables();
setupBrowserDrivers(); prepareBrowsers();
cleanFoldersAndSetUpOpenViduJavaClient(); cleanFoldersAndSetUpOpenViduJavaClient();
} }
@ -86,7 +86,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
void individualDynamicRecordTest() throws Exception { void individualDynamicRecordTest() throws Exception {
isRecordingTest = true; isRecordingTest = true;
setupBrowser("chrome"); MyUser user = setupBrowser("chrome");
log.info("Individual dynamic record"); log.info("Individual dynamic record");
@ -165,7 +165,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
restClient.rest(HttpMethod.POST, "/openvidu/api/recordings/stop/" + sessionName, HttpStatus.SC_OK); restClient.rest(HttpMethod.POST, "/openvidu/api/recordings/stop/" + sessionName, HttpStatus.SC_OK);
user.getEventManager().waitUntilEventReaches("recordingStopped", 3); user.getEventManager().waitUntilEventReaches("recordingStopped", 3);
gracefullyLeaveParticipants(3); gracefullyLeaveParticipants(user, 3);
String recPath = "/opt/openvidu/recordings/" + sessionName + "/"; String recPath = "/opt/openvidu/recordings/" + sessionName + "/";
Recording recording = new OpenVidu(OpenViduTestAppE2eTest.OPENVIDU_URL, OpenViduTestAppE2eTest.OPENVIDU_SECRET) Recording recording = new OpenVidu(OpenViduTestAppE2eTest.OPENVIDU_URL, OpenViduTestAppE2eTest.OPENVIDU_SECRET)
@ -307,7 +307,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
Assert.assertFalse("Wrong record Connection property", connection.record()); Assert.assertFalse("Wrong record Connection property", connection.record());
Assert.assertEquals("Wrong data Connection property", "MY_SERVER_PRO_DATA", connection.getServerData()); Assert.assertEquals("Wrong data Connection property", "MY_SERVER_PRO_DATA", connection.getServerData());
setupBrowser("chrome"); MyUser user = setupBrowser("chrome");
user.getDriver().findElement(By.id("add-user-btn")).click(); user.getDriver().findElement(By.id("add-user-btn")).click();
user.getDriver().findElement(By.id("session-settings-btn-0")).click(); user.getDriver().findElement(By.id("session-settings-btn-0")).click();
@ -567,7 +567,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
restClient.rest(HttpMethod.POST, "/openvidu/api/restart", body, 200); restClient.rest(HttpMethod.POST, "/openvidu/api/restart", body, 200);
waitUntilOpenViduRestarted(30); waitUntilOpenViduRestarted(30);
setupBrowser("chrome"); MyUser user = setupBrowser("chrome");
user.getDriver().findElement(By.id("add-user-btn")).click(); user.getDriver().findElement(By.id("add-user-btn")).click();
user.getDriver().findElement(By.className("join-btn")).click(); user.getDriver().findElement(By.className("join-btn")).click();
@ -602,7 +602,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
user.getEventManager().waitUntilEventReaches("networkQualityLevelChanged", 2); user.getEventManager().waitUntilEventReaches("networkQualityLevelChanged", 2);
if (!latch1.await(30000, TimeUnit.MILLISECONDS)) { if (!latch1.await(30000, TimeUnit.MILLISECONDS)) {
gracefullyLeaveParticipants(1); gracefullyLeaveParticipants(user, 1);
fail(); fail();
return; return;
} }
@ -622,7 +622,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
.findElement(By.cssSelector("#openvidu-instance-1 .mat-expansion-panel:last-child .event-content")) .findElement(By.cssSelector("#openvidu-instance-1 .mat-expansion-panel:last-child .event-content"))
.getAttribute("textContent").contains(connectionId)); .getAttribute("textContent").contains(connectionId));
gracefullyLeaveParticipants(1); gracefullyLeaveParticipants(user, 1);
} }
private void waitUntilOpenViduRestarted(int maxSecondsWait) throws Exception { private void waitUntilOpenViduRestarted(int maxSecondsWait) throws Exception {

View File

@ -47,7 +47,7 @@
<version.junit>4.13.1</version.junit> <version.junit>4.13.1</version.junit>
<version.junit.jupiter>5.7.0</version.junit.jupiter> <version.junit.jupiter>5.7.0</version.junit.jupiter>
<version.junit.platform>1.7.0</version.junit.platform> <version.junit.platform>1.7.0</version.junit.platform>
<version.selenium>3.141.59</version.selenium> <version.selenium>4.0.0</version.selenium>
<version.mockito.core>3.6.0</version.mockito.core> <version.mockito.core>3.6.0</version.mockito.core>
<version.powermock>2.0.9</version.powermock> <version.powermock>2.0.9</version.powermock>
<version.hamcrest>2.2</version.hamcrest> <version.hamcrest>2.2</version.hamcrest>
@ -60,6 +60,7 @@
<version.unirest>1.4.9</version.unirest> <version.unirest>1.4.9</version.unirest>
<version.jcodec>0.2.5</version.jcodec> <version.jcodec>0.2.5</version.jcodec>
<version.commons-validator>1.7</version.commons-validator> <version.commons-validator>1.7</version.commons-validator>
<version.testcontainers>1.16.2</version.testcontainers>
<version.webdrivermanager>4.2.2</version.webdrivermanager> <version.webdrivermanager>4.2.2</version.webdrivermanager>