List of usage examples for org.openqa.selenium.firefox FirefoxProfile setPreference
public void setPreference(String key, Object value)
From source file:org.cerberus.service.engine.impl.SeleniumServerService.java
License:Open Source License
private DesiredCapabilities setFirefoxProfile(TestCaseExecution tCExecution) throws CerberusException { FirefoxProfile profile = new FirefoxProfile(); profile.setEnableNativeEvents(true); profile.setAcceptUntrustedCertificates(true); profile.setPreference("network.http.connection-timeout", "300"); try {//from w w w .j av a2s. c om Invariant invariant = this.invariantService.findInvariantByIdValue("COUNTRY", tCExecution.getCountry()); if (invariant.getGp2() == null) { MyLogger.log(Selenium.class.getName(), Level.WARN, "Country selected (" + tCExecution.getCountry() + ") has no value of GP2 in Invariant table, default language set to English(en)"); profile.setPreference("intl.accept_languages", "en"); } else { profile.setPreference("intl.accept_languages", invariant.getGp2()); } } catch (CerberusException ex) { MyLogger.log(Selenium.class.getName(), Level.WARN, "Country selected (" + tCExecution.getCountry() + ") not in Invariant table, default language set to English(en)"); profile.setPreference("intl.accept_languages", "en"); } if (tCExecution.getVerbose() > 0) { String firebugPath = parameterService .findParameterByKey("cerberus_selenium_firefoxextension_firebug", "").getValue(); String netexportPath = parameterService .findParameterByKey("cerberus_selenium_firefoxextension_netexport", "").getValue(); if (StringUtil.isNullOrEmpty(firebugPath)) { MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM); mes.setDescription(mes.getDescription().replaceAll("%MES%", "Mandatory parameter for network traffic 'cerberus_selenium_firefoxextension_firebug' not defined.")); throw new CerberusException(mes); } if (StringUtil.isNullOrEmpty(netexportPath)) { MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM); mes.setDescription(mes.getDescription().replaceAll("%MES%", "Mandatory parameter for network traffic 'cerberus_selenium_firefoxextension_netexport' not defined.")); throw new CerberusException(mes); } File firebug = new File(firebugPath); if (!firebug.canRead()) { MyLogger.log(Selenium.class.getName(), Level.WARN, "Can't read : " + firebugPath); MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM); mes.setDescription(mes.getDescription().replaceAll("%MES%", "File not found : '" + firebugPath + "' Change the Cerberus parameter : cerberus_selenium_firefoxextension_firebug")); throw new CerberusException(mes); } try { MyLogger.log(SeleniumServerService.class.getName(), Level.DEBUG, "Adding firebug extension : " + firebugPath); profile.addExtension(firebug); } catch (IOException exception) { MyLogger.log(Selenium.class.getName(), Level.WARN, exception.toString()); MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM); mes.setDescription(mes.getDescription().replaceAll("%MES%", "File not found : " + firebugPath)); throw new CerberusException(mes); } File netExport = new File(netexportPath); if (!netExport.canRead()) { MyLogger.log(Selenium.class.getName(), Level.WARN, "Can't read : " + netexportPath); MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM); mes.setDescription(mes.getDescription().replaceAll("%MES%", "File not found : " + netexportPath + "' Change the Cerberus parameter : cerberus_selenium_firefoxextension_netexport")); throw new CerberusException(mes); } try { MyLogger.log(SeleniumServerService.class.getName(), Level.DEBUG, "Adding netexport extension : " + netexportPath); profile.addExtension(netExport); } catch (IOException exception) { MyLogger.log(Selenium.class.getName(), Level.WARN, exception.toString()); MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM); mes.setDescription(mes.getDescription().replaceAll("%MES%", "File not found : " + netexportPath)); throw new CerberusException(mes); } String cerberusUrl = parameterService.findParameterByKey("cerberus_url", "").getValue(); if (StringUtil.isNullOrEmpty(cerberusUrl)) { MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM); mes.setDescription(mes.getDescription().replaceAll("%MES%", "Mandatory parameter for network traffic 'cerberus_url' not defined.")); throw new CerberusException(mes); } // Set default Firefox preferences profile.setPreference("app.update.enabled", false); // Set default Firebug preferences profile.setPreference("extensions.firebug.currentVersion", "1.11.4"); profile.setPreference("extensions.firebug.allPagesActivation", "on"); profile.setPreference("extensions.firebug.defaultPanelName", "net"); profile.setPreference("extensions.firebug.net.enableSites", true); // Set default NetExport preferences profile.setPreference("extensions.firebug.netexport.alwaysEnableAutoExport", true); // Export to Server. String url = cerberusUrl + "/SaveStatistic?logId=" + tCExecution.getExecutionUUID(); profile.setPreference("extensions.firebug.netexport.autoExportToServer", true); profile.setPreference("extensions.firebug.netexport.beaconServerURL", url); MyLogger.log(SeleniumServerService.class.getName(), Level.DEBUG, "Selenium netexport.beaconServerURL : " + url); profile.setPreference("extensions.firebug.netexport.sendToConfirmation", false); profile.setPreference("extensions.firebug.netexport.showPreview", false); } //if userAgent if (!("").equals(tCExecution.getUserAgent())) { profile.setPreference("general.useragent.override", tCExecution.getUserAgent()); } DesiredCapabilities dc = DesiredCapabilities.firefox(); dc.setCapability(FirefoxDriver.PROFILE, profile); return dc; }
From source file:org.cerberus.serviceEngine.impl.SeleniumService.java
License:Open Source License
private DesiredCapabilities setFirefoxProfile(String executionUUID, boolean record, String country) throws CerberusException { FirefoxProfile profile = new FirefoxProfile(); profile.setEnableNativeEvents(true); profile.setAcceptUntrustedCertificates(true); profile.setPreference("network.http.connection-timeout", "300"); try {/*from www .j a va 2 s.c o m*/ Invariant invariant = this.invariantService.findInvariantByIdValue("COUNTRY", country); if (invariant.getGp2() == null) { MyLogger.log(Selenium.class.getName(), Level.WARN, "Country selected (" + country + ") has no value of GP2 in Invariant table, default language set to English(en)"); profile.setPreference("intl.accept_languages", "en"); } else { profile.setPreference("intl.accept_languages", invariant.getGp2()); } } catch (CerberusException ex) { MyLogger.log(Selenium.class.getName(), Level.WARN, "Country selected (" + country + ") not in Invariant table, default language set to English(en)"); profile.setPreference("intl.accept_languages", "en"); } if (record) { String firebugPath = parameterService .findParameterByKey("cerberus_selenium_firefoxextension_firebug", "").getValue(); String netexportPath = parameterService .findParameterByKey("cerberus_selenium_firefoxextension_netexport", "").getValue(); if (StringUtil.isNullOrEmpty(firebugPath)) { MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM); mes.setDescription(mes.getDescription().replaceAll("%MES%", "Mandatory parameter for network traffic 'cerberus_selenium_firefoxextension_firebug' not defined.")); throw new CerberusException(mes); } if (StringUtil.isNullOrEmpty(netexportPath)) { MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM); mes.setDescription(mes.getDescription().replaceAll("%MES%", "Mandatory parameter for network traffic 'cerberus_selenium_firefoxextension_netexport' not defined.")); throw new CerberusException(mes); } File firebug = new File(firebugPath); if (!firebug.canRead()) { MyLogger.log(Selenium.class.getName(), Level.WARN, "Can't read : " + firebugPath); MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM); mes.setDescription(mes.getDescription().replaceAll("%MES%", "File not found : '" + firebugPath + "' Change the Cerberus parameter : cerberus_selenium_firefoxextension_firebug")); throw new CerberusException(mes); } try { MyLogger.log(SeleniumService.class.getName(), Level.DEBUG, "Adding firebug extension : " + firebugPath); profile.addExtension(firebug); } catch (IOException exception) { MyLogger.log(Selenium.class.getName(), Level.WARN, exception.toString()); MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM); mes.setDescription(mes.getDescription().replaceAll("%MES%", "File not found : " + firebugPath)); throw new CerberusException(mes); } File netExport = new File(netexportPath); if (!netExport.canRead()) { MyLogger.log(Selenium.class.getName(), Level.WARN, "Can't read : " + netexportPath); MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM); mes.setDescription(mes.getDescription().replaceAll("%MES%", "File not found : " + netexportPath + "' Change the Cerberus parameter : cerberus_selenium_firefoxextension_netexport")); throw new CerberusException(mes); } try { MyLogger.log(SeleniumService.class.getName(), Level.DEBUG, "Adding netexport extension : " + netexportPath); profile.addExtension(netExport); } catch (IOException exception) { MyLogger.log(Selenium.class.getName(), Level.WARN, exception.toString()); MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM); mes.setDescription(mes.getDescription().replaceAll("%MES%", "File not found : " + netexportPath)); throw new CerberusException(mes); } String cerberusUrl = parameterService.findParameterByKey("cerberus_url", "").getValue(); if (StringUtil.isNullOrEmpty(cerberusUrl)) { MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM); mes.setDescription(mes.getDescription().replaceAll("%MES%", "Mandatory parameter for network traffic 'cerberus_url' not defined.")); throw new CerberusException(mes); } // Set default Firefox preferences profile.setPreference("app.update.enabled", false); // Set default Firebug preferences profile.setPreference("extensions.firebug.currentVersion", "1.11.4"); profile.setPreference("extensions.firebug.allPagesActivation", "on"); profile.setPreference("extensions.firebug.defaultPanelName", "net"); profile.setPreference("extensions.firebug.net.enableSites", true); // Set default NetExport preferences profile.setPreference("extensions.firebug.netexport.alwaysEnableAutoExport", true); // Export to Server. String url = cerberusUrl + "/SaveStatistic?logId=" + executionUUID; profile.setPreference("extensions.firebug.netexport.autoExportToServer", true); profile.setPreference("extensions.firebug.netexport.beaconServerURL", url); MyLogger.log(SeleniumService.class.getName(), Level.DEBUG, "Selenium netexport.beaconServerURL : " + url); // Export to File. This only works on the selenium server side so should not be used as we don't know where to put the file and neither if Linux or Windows based. // String cerberusHarPath = "logHar" + myFile.separator; // String cerberusHarPath = "logHar" ; // File dir = new File(cerberusHarPath + runId); // dir.mkdirs(); // profile.setPreference("extensions.firebug.netexport.autoExportToFile", true); // profile.setPreference("extensions.firebug.netexport.defaultLogDir", cerberusHarPath ); // MyLogger.log(SeleniumService.class.getName(), Level.DEBUG, "Selenium netexport.defaultLogDir : " + cerberusHarPath); profile.setPreference("extensions.firebug.netexport.sendToConfirmation", false); profile.setPreference("extensions.firebug.netexport.showPreview", false); } DesiredCapabilities dc = DesiredCapabilities.firefox(); dc.setCapability(FirefoxDriver.PROFILE, profile); return dc; }
From source file:org.core.FirefoxBenchmark.java
License:Open Source License
@Override protected WebDriver getWebDriver(TestCase test) { FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("general.useragent.override", "Mozilla/5.0 (Linux; U; Android 2.1-update1; de-de; HTC Desire 1.19.161.5 Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17"); profile.setPreference("network.http.proxy.pipelining", true); if (test.getProxy() != null && !test.getProxy().equals("")) { String[] hostAndPort = test.getProxy().split(":"); String host = hostAndPort[0]; Integer port = Integer.valueOf(hostAndPort[1]); profile.setPreference("network.proxy.type", 1); profile.setPreference("network.proxy.http", host); profile.setPreference("network.proxy.http_port", port); }/*from w w w. j av a2 s . c o m*/ return new FirefoxDriver(profile); }
From source file:org.cybercat.automation.browsers.FirefoxProfiler.java
License:Apache License
public FirefoxProfile addNetExportPreferences(FirefoxProfile firefoxProfile) { firefoxProfile.setPreference("app.update.enabled", false); String domain = "extensions.firebug."; // Set default Firebug preferences firefoxProfile.setPreference(domain + "currentVersion", "1.10.6"); firefoxProfile.setPreference(domain + "allPagesActivation", "on"); firefoxProfile.setPreference(domain + "defaultPanelName", "net"); firefoxProfile.setPreference(domain + "net.enableSites", true); // Set default NetExport preferences firefoxProfile.setPreference(domain + "netexport.alwaysEnableAutoExport", true); firefoxProfile.setPreference(domain + "netexport.showPreview", false); firefoxProfile.setPreference(domain + "netexport.pageLoadedTimeout", "60000"); firefoxProfile.setPreference(domain + "netexport.defaultLogDir", Paths.get(WorkFolder.Log.getPath().toString(), "har").toString()); return firefoxProfile; }
From source file:org.eclipse.scout.rt.testing.ui.rap.RapMock.java
License:Open Source License
@Override public void beforeTest() { if (m_service != null) { if (useChrome) { DesiredCapabilities chrome = DesiredCapabilities.chrome(); m_driver = new RemoteWebDriver(m_service.getUrl(), chrome); }// w w w .j ava 2s. c o m } else { if (useFirefox) { System.setProperty("webdriver.firefox.bin", "C:/FirefoxPortableTest_11/App/Firefox/firefox.exe"); FirefoxProfile firefoxProfile = new FirefoxProfile(); if (useFirebug) { try { firefoxProfile.addExtension(new File("E:/Downloads/java/firebug-1.9.2-fx.xpi")); firefoxProfile.setPreference("extensions.firebug.currentVersion", "1.9.2"); // Avoid startup screen firefoxProfile.addExtension(new File("E:/Downloads/java/firepath-0.9.7-fx.xpi")); } catch (IOException e) { throw new IllegalStateException("Could not add/find firefox extensions.", e); } } m_driver = new FirefoxDriver(firefoxProfile); // m_driver = new FirefoxDriver(new FirefoxProfile(new File("C:/Temp/webdriver-profile"))); } } if (m_driver == null) { throw new NullPointerException("no driver instantiated!"); } m_bot = new RAPSelenium(m_driver, "http://localhost:8081"); m_actionBuilder = new Actions(m_bot.getWrappedDriver()); m_bot.open("http://localhost:8081/rap"); m_bot.waitForElementPresent("w2"); }
From source file:org.eclipse.skalli.selenium.utils.DriverProvider.java
License:Open Source License
/** * Starts the driver, adds a shutdown hook to stop the driver and navigates to {@link #getHTTPBaseUrl()} *//*from w w w. j a va2s .c o m*/ private static void startDriver() { FirefoxProfile profile = new FirefoxProfile(); //load the browser plugins if (BROWSER_PLUGINS_FOLDER.exists()) { File[] plugins = BROWSER_PLUGINS_FOLDER.listFiles(); for (int i = 0; i < plugins.length; i++) { File plugin = plugins[i]; String name = plugin.getName(); if (!name.toLowerCase().contains(".xpi")) { System.err.println("\"" + name + "\" is not a plugin -> remove from " + BROWSER_PLUGINS_FOLDER); continue; } //pluginName = "firebug-" + FIREBUG_VERSION + ".xpi" //pluginName = "firepath-" + FIREPATH_VERSION + "-fx.xpi" //set up the plugin if needed if (name.toLowerCase().contains("firebug")) { //pluginName = "firebug-" + FIREBUG_VERSION + ".xpi" String version = name.substring("firebug-".length()); version = version.substring(0, version.length() - ".xpi".length()); //avoids that the first run page is shown profile.setPreference("extensions.firebug.currentVersion", version); } //add the plugin try { profile.addExtension(plugin); } catch (IOException e) { System.err.println("could not add extension \"" + name + "\" to the profile\n" + e); e.printStackTrace(); } } } driver = new FirefoxDriver(profile); registerShutdownHook(); driver.get(getHTTPBaseUrl()); copyTestContent(); }
From source file:org.finra.jtaf.ewd.impl.DefaultSessionFactory.java
License:Apache License
/** * //from ww w .jav a2 s . co m * @param ffp * for use in setting the firefox profile for the tests to use * when running firefox */ private static void addPreferences(FirefoxProfile ffp) { ffp.setPreference("capability.policy.default.HTMLDocument.readyState", "allAccess"); ffp.setPreference("capability.policy.default.HTMLDocument.compatMode", "allAccess"); ffp.setPreference("capability.policy.default.Document.compatMode", "allAccess"); ffp.setPreference("capability.policy.default.Location.href", "allAccess"); ffp.setPreference("capability.policy.default.Window.pageXOffset", "allAccess"); ffp.setPreference("capability.policy.default.Window.pageYOffset", "allAccess"); ffp.setPreference("capability.policy.default.Window.frameElement", "allAccess"); ffp.setPreference("capability.policy.default.Window.frameElement.get", "allAccess"); ffp.setPreference("capability.policy.default.Window.QueryInterface", "allAccess"); ffp.setPreference("capability.policy.default.Window.mozInnerScreenY", "allAccess"); ffp.setPreference("capability.policy.default.Window.mozInnerScreenX", "allAccess"); }
From source file:org.glassfish.tyrus.tests.qa.SeleniumToolkit.java
License:Open Source License
public void setUpFirefox() { try {//from ww w .j a v a 2 s. c om FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("network.proxy.type", 0); if (onWindows()) { assert new File(WIN_FIREFOX_BIN).exists() : WIN_FIREFOX_BIN + " exists"; driver = new FirefoxDriver(new FirefoxBinary(new File(WIN_FIREFOX_BIN)), profile); } else { driver = new FirefoxDriver(profile); } commonBrowserSetup(); logger.log(Level.INFO, "FF Setup PASSED"); } catch (Exception ex) { logger.log(Level.SEVERE, "FF Setup FAILED: {0}", ex.getLocalizedMessage()); ex.printStackTrace(); } finally { assert driver != null : "Driver is null"; } }
From source file:org.jitsi.meet.test.ConferenceFixture.java
License:Apache License
/** * Starts a <tt>WebDriver</tt> instance using default settings. * @param browser the browser type./* w w w . ja v a 2s .com*/ * @param participant the participant we are creating a driver for. * @return the <tt>WebDriver</tt> instance. */ private static WebDriver startDriverInstance(BrowserType browser, Participant participant) { // by default we load chrome, but we can load safari or firefox if (browser == BrowserType.firefox) { String browserBinary = System.getProperty(BROWSER_FF_BINARY_NAME_PROP); if (browserBinary != null && browserBinary.trim().length() > 0) { File binaryFile = new File(browserBinary); if (binaryFile.exists()) System.setProperty("webdriver.firefox.bin", browserBinary); } FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("media.navigator.permission.disabled", true); // Enables tcp in firefox, disabled by default in 44 profile.setPreference("media.peerconnection.ice.tcp", true); profile.setAcceptUntrustedCertificates(true); profile.setPreference("webdriver.log.file", FailureListener.createLogsFolder() + "/firefox-js-console-" + getParticipantName(participant) + ".log"); System.setProperty("webdriver.firefox.logfile", FailureListener.createLogsFolder() + "/firefox-console-" + getParticipantName(participant) + ".log"); return new FirefoxDriver(profile); } else if (browser == BrowserType.safari) { return new SafariDriver(); } else if (browser == BrowserType.ie) { DesiredCapabilities caps = DesiredCapabilities.internetExplorer(); caps.setCapability("ignoreZoomSetting", true); System.setProperty("webdriver.ie.driver.silent", "true"); return new InternetExplorerDriver(caps); } else { System.setProperty("webdriver.chrome.verboseLogging", "true"); System.setProperty("webdriver.chrome.logfile", FailureListener.createLogsFolder() + "/chrome-console-" + getParticipantName(participant) + ".log"); DesiredCapabilities caps = DesiredCapabilities.chrome(); LoggingPreferences logPrefs = new LoggingPreferences(); logPrefs.enable(LogType.BROWSER, Level.ALL); caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs); final ChromeOptions ops = new ChromeOptions(); ops.addArguments("use-fake-ui-for-media-stream"); ops.addArguments("use-fake-device-for-media-stream"); ops.addArguments("disable-extensions"); ops.addArguments("disable-plugins"); ops.addArguments("mute-audio"); String disProp = System.getProperty(DISABLE_NOSANBOX_PARAM); if (disProp == null && !Boolean.parseBoolean(disProp)) { ops.addArguments("no-sandbox"); ops.addArguments("disable-setuid-sandbox"); } // starting version 46 we see crashes of chrome GPU process when // running in headless mode // which leaves the browser opened and selenium hang forever. // There are reports that in older version crashes like that will // fallback to software graphics, we try to disable gpu for now ops.addArguments("disable-gpu"); String browserProp; if (participant == Participant.secondParticipantDriver) browserProp = BROWSER_CHROME_BINARY_SECOND_NAME_PROP; else browserProp = BROWSER_CHROME_BINARY_OWNER_NAME_PROP; String browserBinary = System.getProperty(browserProp); if (browserBinary != null && browserBinary.trim().length() > 0) { File binaryFile = new File(browserBinary); if (binaryFile.exists()) ops.setBinary(binaryFile); } if (fakeStreamAudioFName != null) { ops.addArguments("use-file-for-fake-audio-capture=" + fakeStreamAudioFName); } if (fakeStreamVideoFName != null) { ops.addArguments("use-file-for-fake-video-capture=" + fakeStreamVideoFName); } //ops.addArguments("vmodule=\"*media/*=3,*turn*=3\""); ops.addArguments("enable-logging"); ops.addArguments("vmodule=*=3"); caps.setCapability(ChromeOptions.CAPABILITY, ops); try { final ExecutorService pool = Executors.newFixedThreadPool(1); // we will retry four times for 1 minute to obtain // the chrome driver, on headless environments chrome hangs // and we wait forever for (int i = 0; i < 2; i++) { Future<ChromeDriver> future = null; try { future = pool.submit(new Callable<ChromeDriver>() { @Override public ChromeDriver call() throws Exception { long start = System.currentTimeMillis(); ChromeDriver resDr = new ChromeDriver(ops); System.err.println("ChromeDriver created for:" + (System.currentTimeMillis() - start) + " ms."); return resDr; } }); ChromeDriver res = future.get(2, TimeUnit.MINUTES); if (res != null) return res; } catch (TimeoutException te) { // cancel current task if (future != null) future.cancel(true); System.err.println("Timeout waiting for " + "chrome instance! We will retry now, this was our" + "attempt " + i); } } } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } // keep the old code System.err.println("Just create ChromeDriver, may hang!"); return new ChromeDriver(ops); } }
From source file:org.jitsi.meet.test.web.WebParticipantFactory.java
License:Apache License
/** * Starts a <tt>WebDriver</tt> instance using default settings. * @param options the options to use when creating the driver. * @return the <tt>WebDriver</tt> instance. *///from w w w . j ava2s.c o m private WebDriver startWebDriver(WebParticipantOptions options) { ParticipantType participantType = options.getParticipantType(); String version = options.getVersion(); File browserBinaryAPath = getFile(options, options.getBinary()); boolean isRemote = options.isRemote(); // by default we load chrome, but we can load safari or firefox if (participantType.isFirefox()) { FirefoxDriverManager.getInstance().setup(); if (browserBinaryAPath != null && (browserBinaryAPath.exists() || isRemote)) { System.setProperty("webdriver.firefox.bin", browserBinaryAPath.getAbsolutePath()); } FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("media.navigator.permission.disabled", true); // Enables tcp in firefox, disabled by default in 44 profile.setPreference("media.peerconnection.ice.tcp", true); profile.setPreference("media.navigator.streams.fake", true); profile.setAcceptUntrustedCertificates(true); profile.setPreference("webdriver.log.file", FailureListener.createLogsFolder() + "/firefox-js-console-" + options.getName() + ".log"); System.setProperty("webdriver.firefox.logfile", FailureListener.createLogsFolder() + "/firefox-console-" + options.getName() + ".log"); if (isRemote) { FirefoxOptions ffOptions = new FirefoxOptions(); ffOptions.setProfile(profile); if (version != null && version.length() > 0) { ffOptions.setCapability(CapabilityType.VERSION, version); } return new RemoteWebDriver(options.getRemoteDriverAddress(), ffOptions); } return new FirefoxDriver(new FirefoxOptions().setProfile(profile)); } else if (participantType == ParticipantType.safari) { // You must enable the 'Allow Remote Automation' option in // Safari's Develop menu to control Safari via WebDriver. // In Safari->Preferences->Websites, select Camera, // and select Allow for "When visiting other websites" if (isRemote) { return new RemoteWebDriver(options.getRemoteDriverAddress(), new SafariOptions()); } return new SafariDriver(); } else if (participantType == ParticipantType.edge) { InternetExplorerDriverManager.getInstance().setup(); InternetExplorerOptions ieOptions = new InternetExplorerOptions(); ieOptions.ignoreZoomSettings(); System.setProperty("webdriver.ie.driver.silent", "true"); return new InternetExplorerDriver(ieOptions); } else { ChromeDriverManager.getInstance().setup(); System.setProperty("webdriver.chrome.verboseLogging", "true"); System.setProperty("webdriver.chrome.logfile", FailureListener.createLogsFolder() + "/chrome-console-" + options.getName() + ".log"); LoggingPreferences logPrefs = new LoggingPreferences(); logPrefs.enable(LogType.BROWSER, Level.ALL); final ChromeOptions ops = new ChromeOptions(); ops.addArguments("use-fake-ui-for-media-stream"); ops.addArguments("use-fake-device-for-media-stream"); ops.addArguments("disable-plugins"); ops.addArguments("mute-audio"); ops.addArguments("disable-infobars"); // Since chrome v66 there are new autoplay policies, which broke // shared video tests, disable no-user-gesture to make it work ops.addArguments("autoplay-policy=no-user-gesture-required"); if (options.getChromeExtensionId() != null) { try { ops.addExtensions(downloadExtension(options.getChromeExtensionId())); } catch (IOException e) { throw new RuntimeException(e); } } ops.addArguments("auto-select-desktop-capture-source=Entire screen"); ops.setCapability(CapabilityType.LOGGING_PREFS, logPrefs); if (options.isChromeSandboxDisabled()) { ops.addArguments("no-sandbox"); ops.addArguments("disable-setuid-sandbox"); } if (options.isHeadless()) { ops.addArguments("headless"); ops.addArguments("window-size=1200x600"); } // starting version 46 we see crashes of chrome GPU process when // running in headless mode // which leaves the browser opened and selenium hang forever. // There are reports that in older version crashes like that will // fallback to software graphics, we try to disable gpu for now ops.addArguments("disable-gpu"); if (browserBinaryAPath != null && (browserBinaryAPath.exists() || isRemote)) { ops.setBinary(browserBinaryAPath.getAbsolutePath()); } File uplinkFile = getFile(options, options.getUplink()); if (uplinkFile != null) { ops.addArguments("uplink=" + uplinkFile.getAbsolutePath()); } File downlinkFile = getFile(options, options.getDownlink()); if (downlinkFile != null) { ops.addArguments("downlink=" + downlinkFile.getAbsolutePath()); } String profileDirectory = options.getProfileDirectory(); if (profileDirectory != null && profileDirectory != "") { ops.addArguments("user-data-dir=" + profileDirectory); } File fakeStreamAudioFile = getFile(options, options.getFakeStreamAudioFile()); if (fakeStreamAudioFile != null) { ops.addArguments("use-file-for-fake-audio-capture=" + fakeStreamAudioFile.getAbsolutePath()); } File fakeStreamVideoFile = getFile(options, options.getFakeStreamVideoFile()); if (fakeStreamVideoFile != null) { ops.addArguments("use-file-for-fake-video-capture=" + fakeStreamVideoFile.getAbsolutePath()); } //ops.addArguments("vmodule=\"*media/*=3,*turn*=3\""); ops.addArguments("enable-logging"); ops.addArguments("vmodule=*=3"); if (isRemote) { if (version != null && version.length() > 0) { ops.setCapability(CapabilityType.VERSION, version); } return new RemoteWebDriver(options.getRemoteDriverAddress(), ops); } try { final ExecutorService pool = Executors.newFixedThreadPool(1); // we will retry four times for 1 minute to obtain // the chrome driver, on headless environments chrome hangs // and we wait forever for (int i = 0; i < 2; i++) { Future<ChromeDriver> future = null; try { future = pool.submit(() -> { long start = System.currentTimeMillis(); ChromeDriver resDr = new ChromeDriver(ops); TestUtils.print( "ChromeDriver created for:" + (System.currentTimeMillis() - start) + " ms."); return resDr; }); ChromeDriver res = future.get(2, TimeUnit.MINUTES); if (res != null) return res; } catch (TimeoutException te) { // cancel current task future.cancel(true); TestUtils.print("Timeout waiting for " + "chrome instance! We will retry now, this was our" + "attempt " + i); } } } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } // keep the old code TestUtils.print("Just create ChromeDriver, may hang!"); return new ChromeDriver(ops); } }