openvidu-test-browsers: add "chromeFakeAudio"

pull/748/head
pabloFuente 2022-10-19 12:45:58 +02:00
parent cc8ac8d99d
commit ed82ab1241
4 changed files with 95 additions and 69 deletions

View File

@ -32,89 +32,104 @@ import org.openqa.selenium.remote.RemoteWebDriver;
public class ChromeUser extends BrowserUser { public class ChromeUser extends BrowserUser {
public ChromeUser(String userName, int timeOfWaitInSeconds, boolean headless) { public ChromeUser(String userName, int timeOfWaitInSeconds, boolean headless) {
this(userName, timeOfWaitInSeconds, generateDefaultScreenChromeOptions(), headless); this(userName, timeOfWaitInSeconds, generateDefaultScreenChromeOptions(), headless);
} }
public ChromeUser(String userName, int timeOfWaitInSeconds, String screenToCapture) { public ChromeUser(String userName, int timeOfWaitInSeconds, String screenToCapture) {
this(userName, timeOfWaitInSeconds, this(userName, timeOfWaitInSeconds,
generateCustomScreenChromeOptions(screenToCapture, Paths.get("/opt/openvidu/fakeaudio.wav")), false); generateCustomScreenChromeOptions(screenToCapture, Paths.get("/opt/openvidu/fakeaudio.wav")), false);
} }
public ChromeUser(String userName, int timeOfWaitInSeconds, Path fakeVideoLocation) { public ChromeUser(String userName, int timeOfWaitInSeconds, Path fakeVideoLocation) {
this(userName, timeOfWaitInSeconds, generateFakeVideoChromeOptions(fakeVideoLocation), true); this(userName, timeOfWaitInSeconds, generateFakeVideoAudioChromeOptions(fakeVideoLocation, null), true);
} }
public ChromeUser(String userName, int timeOfWaitInSeconds, Path fakeVideoLocation, boolean headless) { public ChromeUser(String userName, int timeOfWaitInSeconds, Path fakeVideoLocation, boolean headless) {
this(userName, timeOfWaitInSeconds, generateFakeVideoChromeOptions(fakeVideoLocation), headless); this(userName, timeOfWaitInSeconds, generateFakeVideoAudioChromeOptions(fakeVideoLocation, null), headless);
} }
private ChromeUser(String userName, int timeOfWaitInSeconds, ChromeOptions options, boolean headless) { public ChromeUser(String userName, int timeOfWaitInSeconds, Path fakeVideoLocation, Path fakeAudioLocation) {
super(userName, timeOfWaitInSeconds); this(userName, timeOfWaitInSeconds, generateFakeVideoAudioChromeOptions(fakeVideoLocation, fakeAudioLocation),
true);
}
String REMOTE_URL = System.getProperty("REMOTE_URL_CHROME"); public ChromeUser(String userName, int timeOfWaitInSeconds, Path fakeVideoLocation, Path fakeAudioLocation,
boolean headless) {
this(userName, timeOfWaitInSeconds, generateFakeVideoAudioChromeOptions(fakeVideoLocation, fakeAudioLocation),
headless);
}
options.setAcceptInsecureCerts(true); private ChromeUser(String userName, int timeOfWaitInSeconds, ChromeOptions options, boolean headless) {
options.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.IGNORE); super(userName, timeOfWaitInSeconds);
if (REMOTE_URL != null && headless) { String REMOTE_URL = System.getProperty("REMOTE_URL_CHROME");
options.setHeadless(true);
}
options.addArguments("--disable-infobars"); options.setAcceptInsecureCerts(true);
options.setExperimentalOption("excludeSwitches", new String[] { "enable-automation" }); options.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.IGNORE);
Map<String, Object> prefs = new HashMap<String, Object>(); if (REMOTE_URL != null && headless) {
prefs.put("profile.default_content_setting_values.media_stream_mic", 1); options.setHeadless(true);
prefs.put("profile.default_content_setting_values.media_stream_camera", 1); }
options.setExperimentalOption("prefs", prefs);
if (REMOTE_URL != null) { options.addArguments("--disable-infobars");
log.info("Using URL {} to connect to remote web driver", REMOTE_URL); options.setExperimentalOption("excludeSwitches", new String[] { "enable-automation" });
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 ChromeDriver(options);
}
this.driver.manage().timeouts().setScriptTimeout(timeOfWaitInSeconds, TimeUnit.SECONDS); Map<String, Object> prefs = new HashMap<String, Object>();
this.configureDriver(new org.openqa.selenium.Dimension(1920, 1080)); prefs.put("profile.default_content_setting_values.media_stream_mic", 1);
} prefs.put("profile.default_content_setting_values.media_stream_camera", 1);
options.setExperimentalOption("prefs", prefs);
private static ChromeOptions generateDefaultScreenChromeOptions() { if (REMOTE_URL != null) {
ChromeOptions options = new ChromeOptions(); log.info("Using URL {} to connect to remote web driver", REMOTE_URL);
// This flag avoids to grant the user media try {
options.addArguments("--use-fake-ui-for-media-stream"); this.driver = new RemoteWebDriver(new URL(REMOTE_URL), options);
// This flag fakes user media with synthetic video } catch (MalformedURLException e) {
options.addArguments("--use-fake-device-for-media-stream"); e.printStackTrace();
// This flag selects the entire screen as video source when screen sharing }
options.addArguments("--auto-select-desktop-capture-source=Entire screen"); } else {
return options; log.info("Using local web driver");
} this.driver = new ChromeDriver(options);
}
private static ChromeOptions generateCustomScreenChromeOptions(String screenToCapture, Path audioFileLocation) { this.driver.manage().timeouts().setScriptTimeout(timeOfWaitInSeconds, TimeUnit.SECONDS);
ChromeOptions options = new ChromeOptions(); this.configureDriver(new org.openqa.selenium.Dimension(1920, 1080));
// This flag selects the entire screen as video source when screen sharing }
options.addArguments("--auto-select-desktop-capture-source=" + screenToCapture);
options.addArguments("--use-fake-device-for-media-stream");
options.addArguments("--use-file-for-fake-audio-capture=" + audioFileLocation.toString());
return options; private static ChromeOptions generateDefaultScreenChromeOptions() {
} ChromeOptions options = new ChromeOptions();
// 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");
// This flag selects the entire screen as video source when screen sharing
options.addArguments("--auto-select-desktop-capture-source=Entire screen");
return options;
}
private static ChromeOptions generateFakeVideoChromeOptions(Path videoFileLocation) { private static ChromeOptions generateCustomScreenChromeOptions(String screenToCapture, Path audioFileLocation) {
ChromeOptions options = new ChromeOptions(); ChromeOptions options = new ChromeOptions();
// This flag avoids to grant the user media // This flag selects the entire screen as video source when screen sharing
options.addArguments("--use-fake-ui-for-media-stream"); options.addArguments("--auto-select-desktop-capture-source=" + screenToCapture);
// This flag fakes user media with synthetic video options.addArguments("--use-fake-device-for-media-stream");
options.addArguments("--use-fake-device-for-media-stream"); options.addArguments("--use-file-for-fake-audio-capture=" + audioFileLocation.toString());
// This flag sets the video input as
options.addArguments("--use-file-for-fake-video-capture=" + videoFileLocation.toString()); return options;
return options; }
}
private static ChromeOptions generateFakeVideoAudioChromeOptions(Path videoFileLocation, Path audioFileLocation) {
ChromeOptions options = new ChromeOptions();
// 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");
if (videoFileLocation != null) {
options.addArguments("--use-file-for-fake-video-capture=" + videoFileLocation.toString());
}
if (audioFileLocation != null) {
options.addArguments("--use-file-for-fake-audio-capture=" + audioFileLocation.toString());
}
return options;
}
} }

View File

@ -123,6 +123,11 @@
<artifactId>testcontainers</artifactId> <artifactId>testcontainers</artifactId>
<version>${version.testcontainers}</version> <version>${version.testcontainers}</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>${version.commons-text}</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -335,6 +335,11 @@ public class OpenViduTestE2e {
setupBrowserAux(BrowserNames.CHROME, container, false); setupBrowserAux(BrowserNames.CHROME, container, false);
browserUser = new ChromeUser("TestUser", 50, Paths.get("/opt/openvidu/barcode.y4m")); browserUser = new ChromeUser("TestUser", 50, Paths.get("/opt/openvidu/barcode.y4m"));
break; break;
case "chromeFakeAudio":
container = chromeContainer("selenium/standalone-chrome:" + CHROME_VERSION, 2147483648L, 1, true);
setupBrowserAux(BrowserNames.CHROME, container, false);
browserUser = new ChromeUser("TestUser", 50, null, Paths.get("/opt/openvidu/stt-test2.wav"));
break;
case "chromeVirtualBackgroundFakeVideo": case "chromeVirtualBackgroundFakeVideo":
container = chromeContainer("selenium/standalone-chrome:" + CHROME_VERSION, 2147483648L, 1, false); container = chromeContainer("selenium/standalone-chrome:" + CHROME_VERSION, 2147483648L, 1, false);
setupBrowserAux(BrowserNames.CHROME, container, false); setupBrowserAux(BrowserNames.CHROME, container, false);

View File

@ -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.commons-text>1.10.0</version.commons-text>
<version.testcontainers>1.16.2</version.testcontainers> <version.testcontainers>1.16.2</version.testcontainers>
<version.appium>7.6.0</version.appium> <version.appium>7.6.0</version.appium>