openvidu-test-e2e: tests extended for StreamPropertyChangedEvent

pull/88/merge
pabloFuente 2018-07-03 15:59:15 +02:00
parent 366d616d4f
commit 92f14b8c0b
3 changed files with 148 additions and 3 deletions

View File

@ -36,6 +36,7 @@ import org.junit.platform.runner.JUnitPlatform;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Keys;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
@ -48,6 +49,7 @@ import io.github.bonigarcia.wdm.ChromeDriverManager;
import io.github.bonigarcia.wdm.FirefoxDriverManager;
import io.openvidu.test.e2e.browser.BrowserUser;
import io.openvidu.test.e2e.browser.ChromeAndroidUser;
import io.openvidu.test.e2e.browser.ChromeUser;
import io.openvidu.test.e2e.browser.FirefoxUser;
@ -106,6 +108,9 @@ public class OpenViduTestAppE2eTest {
case "firefox":
this.user = new FirefoxUser("TestUser", 50);
break;
case "chromeAndroid":
this.user = new ChromeAndroidUser("TestUser", 50);
break;
default:
this.user = new ChromeUser("TestUser", 50);
}
@ -722,6 +727,76 @@ public class OpenViduTestAppE2eTest {
}
@Test
@DisplayName("Stream property changed event")
void streamPropertyChangedEvent() throws Exception {
Queue<Boolean> threadAssertions = new ConcurrentLinkedQueue<Boolean>();
setupBrowser("chrome");
log.info("Stream property changed event");
WebElement oneToManyInput = user.getDriver().findElement(By.id("one2many-input"));
oneToManyInput.clear();
oneToManyInput.sendKeys("1");
user.getDriver().findElement(By.id("one2many-btn")).click();
user.getDriver().findElement(By.className("screen-radio")).click();
List<WebElement> joinButtons = user.getDriver().findElements(By.className("join-btn"));
for (WebElement el : joinButtons) {
el.sendKeys(Keys.ENTER);
}
user.getEventManager().waitUntilEventReaches("connectionCreated", 4);
user.getEventManager().waitUntilEventReaches("accessAllowed", 1);
user.getEventManager().waitUntilEventReaches("streamCreated", 2);
user.getEventManager().waitUntilEventReaches("streamPlaying", 2);
// Unpublish video
user.getEventManager().on("streamPropertyChanged", (event) -> {
threadAssertions.add(((String) event.get("eventContent")).contains("videoActive [false]"));
});
user.getDriver().findElements(By.className("pub-video-btn")).get(0).click();
user.getEventManager().waitUntilEventReaches("streamPropertyChanged", 2);
user.getEventManager().off("streamPropertyChanged");
for (Iterator<Boolean> iter = threadAssertions.iterator(); iter.hasNext();) {
Assert.assertTrue(iter.next());
iter.remove();
}
// Unpublish audio
user.getEventManager().on("streamPropertyChanged", (event) -> {
threadAssertions.add(((String) event.get("eventContent")).contains("audioActive [false]"));
});
user.getDriver().findElements(By.className("pub-audio-btn")).get(0).click();
user.getEventManager().waitUntilEventReaches("streamPropertyChanged", 4);
user.getEventManager().off("streamPropertyChanged");
for (Iterator<Boolean> iter = threadAssertions.iterator(); iter.hasNext();) {
Assert.assertTrue(iter.next());
iter.remove();
}
// Resize captured window
int newWidth = 1280;
int newHeight = 720;
user.getEventManager().on("streamPropertyChanged", (event) -> {
threadAssertions.add(((String) event.get("eventContent"))
.contains("videoDimensions videoDimensions [{\\\"width\\\":" + newWidth + ",\\\"height\\\":" + newHeight + "}]"));
});
user.getDriver().manage().window().setSize(new Dimension(newWidth, newHeight));
user.getEventManager().waitUntilEventReaches("streamPropertyChanged", 6);
user.getEventManager().off("streamPropertyChanged");
for (Iterator<Boolean> iter = threadAssertions.iterator(); iter.hasNext();) {
Assert.assertTrue(iter.next());
iter.remove();
}
gracefullyLeaveParticipants(2);
}
@Test
@DisplayName("Local record")
void localRecordTest() throws Exception {
@ -905,6 +980,8 @@ public class OpenViduTestAppE2eTest {
user.getDriver().findElement(By.id("close-dialog-btn")).click();
gracefullyLeaveParticipants(1);
}
private void listEmptyRecordings() {

View File

@ -0,0 +1,68 @@
/*
* (C) Copyright 2017-2018 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.e2e.browser;
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", "Nexus 5");
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("mobileEmulation", mobileEmulation);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setAcceptInsecureCerts(true);
// This flag avoids to grant the user media
options.addArguments("--use-fake-ui-for-media-stream");
// This flag fakes user media with synthetic video
options.addArguments("--use-fake-device-for-media-stream");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
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

@ -41,7 +41,7 @@ public class ChromeUser extends BrowserUser {
// This flag fakes user media with synthetic video
options.addArguments("--use-fake-device-for-media-stream");
// This flag selects the entire screen as video source when screen sharing
options.addArguments("--auto-select-desktop-capture-source=Entire screen");
options.addArguments("--auto-select-desktop-capture-source=OpenVidu TestApp - Google Chrome");
try {
// Add Screen Sharing extension