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 ChromeUser(String userName, int timeOfWaitInSeconds, boolean headless) {
this(userName, timeOfWaitInSeconds, generateDefaultScreenChromeOptions(), headless);
}
public ChromeUser(String userName, int timeOfWaitInSeconds, boolean headless) {
this(userName, timeOfWaitInSeconds, generateDefaultScreenChromeOptions(), headless);
}
public ChromeUser(String userName, int timeOfWaitInSeconds, String screenToCapture) {
this(userName, timeOfWaitInSeconds,
generateCustomScreenChromeOptions(screenToCapture, Paths.get("/opt/openvidu/fakeaudio.wav")), false);
}
public ChromeUser(String userName, int timeOfWaitInSeconds, String screenToCapture) {
this(userName, timeOfWaitInSeconds,
generateCustomScreenChromeOptions(screenToCapture, Paths.get("/opt/openvidu/fakeaudio.wav")), false);
}
public ChromeUser(String userName, int timeOfWaitInSeconds, Path fakeVideoLocation) {
this(userName, timeOfWaitInSeconds, generateFakeVideoChromeOptions(fakeVideoLocation), true);
}
public ChromeUser(String userName, int timeOfWaitInSeconds, Path fakeVideoLocation) {
this(userName, timeOfWaitInSeconds, generateFakeVideoAudioChromeOptions(fakeVideoLocation, null), true);
}
public ChromeUser(String userName, int timeOfWaitInSeconds, Path fakeVideoLocation, boolean headless) {
this(userName, timeOfWaitInSeconds, generateFakeVideoChromeOptions(fakeVideoLocation), headless);
}
public ChromeUser(String userName, int timeOfWaitInSeconds, Path fakeVideoLocation, boolean headless) {
this(userName, timeOfWaitInSeconds, generateFakeVideoAudioChromeOptions(fakeVideoLocation, null), headless);
}
private ChromeUser(String userName, int timeOfWaitInSeconds, ChromeOptions options, boolean headless) {
super(userName, timeOfWaitInSeconds);
public ChromeUser(String userName, int timeOfWaitInSeconds, Path fakeVideoLocation, Path fakeAudioLocation) {
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);
options.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.IGNORE);
private ChromeUser(String userName, int timeOfWaitInSeconds, ChromeOptions options, boolean headless) {
super(userName, timeOfWaitInSeconds);
if (REMOTE_URL != null && headless) {
options.setHeadless(true);
}
String REMOTE_URL = System.getProperty("REMOTE_URL_CHROME");
options.addArguments("--disable-infobars");
options.setExperimentalOption("excludeSwitches", new String[] { "enable-automation" });
options.setAcceptInsecureCerts(true);
options.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.IGNORE);
Map<String, Object> prefs = new HashMap<String, Object>();
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);
if (REMOTE_URL != null && headless) {
options.setHeadless(true);
}
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 ChromeDriver(options);
}
options.addArguments("--disable-infobars");
options.setExperimentalOption("excludeSwitches", new String[] { "enable-automation" });
this.driver.manage().timeouts().setScriptTimeout(timeOfWaitInSeconds, TimeUnit.SECONDS);
this.configureDriver(new org.openqa.selenium.Dimension(1920, 1080));
}
Map<String, Object> prefs = new HashMap<String, Object>();
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() {
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;
}
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 ChromeDriver(options);
}
private static ChromeOptions generateCustomScreenChromeOptions(String screenToCapture, Path audioFileLocation) {
ChromeOptions options = new ChromeOptions();
// 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());
this.driver.manage().timeouts().setScriptTimeout(timeOfWaitInSeconds, TimeUnit.SECONDS);
this.configureDriver(new org.openqa.selenium.Dimension(1920, 1080));
}
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) {
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 sets the video input as
options.addArguments("--use-file-for-fake-video-capture=" + videoFileLocation.toString());
return options;
}
private static ChromeOptions generateCustomScreenChromeOptions(String screenToCapture, Path audioFileLocation) {
ChromeOptions options = new ChromeOptions();
// 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 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>
<version>${version.testcontainers}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>${version.commons-text}</version>
</dependency>
</dependencies>
</project>

View File

@ -335,6 +335,11 @@ public class OpenViduTestE2e {
setupBrowserAux(BrowserNames.CHROME, container, false);
browserUser = new ChromeUser("TestUser", 50, Paths.get("/opt/openvidu/barcode.y4m"));
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":
container = chromeContainer("selenium/standalone-chrome:" + CHROME_VERSION, 2147483648L, 1, false);
setupBrowserAux(BrowserNames.CHROME, container, false);

View File

@ -60,6 +60,7 @@
<version.unirest>1.4.9</version.unirest>
<version.jcodec>0.2.5</version.jcodec>
<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.appium>7.6.0</version.appium>