openvidu-test-e2e: ChromeOptions update to support getDisplayMedia

pull/255/head
pabloFuente 2019-02-25 13:00:05 +01:00
parent 4f3cce732f
commit 6145a49423
1 changed files with 21 additions and 17 deletions

View File

@ -17,26 +17,25 @@
package io.openvidu.test.e2e.browser; package io.openvidu.test.e2e.browser;
import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.remote.RemoteWebDriver;
import org.springframework.core.io.ClassPathResource;
public class ChromeUser extends BrowserUser { public class ChromeUser extends BrowserUser {
public ChromeUser(String userName, int timeOfWaitInSeconds) { public ChromeUser(String userName, int timeOfWaitInSeconds) {
this(userName, timeOfWaitInSeconds, "Entire screen", false); this(userName, timeOfWaitInSeconds, generateDefaultScreenChromeOptions());
} }
public ChromeUser(String userName, int timeOfWaitInSeconds, String screenToCapture, boolean runningAsRoot) { public ChromeUser(String userName, int timeOfWaitInSeconds, String screenToCapture, boolean runningAsRoot) {
this(userName, timeOfWaitInSeconds, generateScreenChromeOptions(screenToCapture, runningAsRoot)); this(userName, timeOfWaitInSeconds, generateCustomScreenChromeOptions(screenToCapture, runningAsRoot));
} }
public ChromeUser(String userName, int timeOfWaitInSeconds, Path fakeVideoLocation) { public ChromeUser(String userName, int timeOfWaitInSeconds, Path fakeVideoLocation) {
@ -45,42 +44,47 @@ public class ChromeUser extends BrowserUser {
private ChromeUser(String userName, int timeOfWaitInSeconds, ChromeOptions options) { private ChromeUser(String userName, int timeOfWaitInSeconds, ChromeOptions options) {
super(userName, timeOfWaitInSeconds); super(userName, timeOfWaitInSeconds);
DesiredCapabilities capabilities = DesiredCapabilities.chrome(); options.setAcceptInsecureCerts(true);
capabilities.setAcceptInsecureCerts(true);
capabilities.setCapability(ChromeOptions.CAPABILITY, options); 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);
String REMOTE_URL = System.getProperty("REMOTE_URL_CHROME"); String REMOTE_URL = System.getProperty("REMOTE_URL_CHROME");
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 ChromeDriver(capabilities); this.driver = new ChromeDriver(options);
} }
this.driver.manage().timeouts().setScriptTimeout(this.timeOfWaitInSeconds, TimeUnit.SECONDS); this.driver.manage().timeouts().setScriptTimeout(this.timeOfWaitInSeconds, TimeUnit.SECONDS);
this.configureDriver(); this.configureDriver();
} }
private static ChromeOptions generateScreenChromeOptions(String screenToCapture, boolean runningAsRoot) { private static ChromeOptions generateDefaultScreenChromeOptions() {
ChromeOptions options = new ChromeOptions(); ChromeOptions options = new ChromeOptions();
// This flag avoids to grant the user media // This flag avoids to grant the user media
options.addArguments("--use-fake-ui-for-media-stream"); options.addArguments("--use-fake-ui-for-media-stream");
// This flag fakes user media with synthetic video // This flag fakes user media with synthetic video
options.addArguments("--use-fake-device-for-media-stream"); options.addArguments("--use-fake-device-for-media-stream");
// This flag selects the entire screen as video source when screen sharing // This flag selects the entire screen as video source when screen sharing
options.addArguments("--auto-select-desktop-capture-source=" + screenToCapture); options.addArguments("--auto-select-desktop-capture-source=Entire screen");
try {
// Add Screen Sharing extension return options;
options.addExtensions(new ClassPathResource("ScreenCapturing.crx").getFile());
} catch (IOException e) {
e.printStackTrace();
} }
private static ChromeOptions generateCustomScreenChromeOptions(String screenToCapture, boolean runningAsRoot) {
ChromeOptions options = new ChromeOptions();
// This flag selects the entire screen as video source when screen sharing
options.addArguments("--auto-select-desktop-capture-source=" + screenToCapture);
if (runningAsRoot) { if (runningAsRoot) {
options.addArguments("--no-sandbox"); options.addArguments("--no-sandbox");
} }