List of usage examples for org.openqa.selenium.firefox FirefoxProfile setPreference
public void setPreference(String key, Object value)
From source file:com.dhenton9000.selenium.generic.GenericAutomationRepository.java
/** * set up the driver with configuration parameters * *///from ww w . j a v a 2 s .co m private void configureDriver() { LoggingPreferences logs = new LoggingPreferences(); logs.enable(LogType.BROWSER, Level.SEVERE); logs.enable(LogType.CLIENT, Level.SEVERE); logs.enable(LogType.DRIVER, Level.SEVERE); logs.enable(LogType.PERFORMANCE, Level.SEVERE); logs.enable(LogType.PROFILER, Level.SEVERE); logs.enable(LogType.SERVER, Level.SEVERE); String driverTypeString = this.config.getString("test.selenium.browser"); if (driverTypeString == null) { throw new RuntimeException("must specify 'test.selenium.browser' in prop file"); } DRIVER_TYPES driverType = DRIVER_TYPES.valueOf(driverTypeString); LOG.debug(" found driver type " + driverType.toString()); if (driverType == null) { throw new RuntimeException("cannot find driver type of " + driverTypeString); } switch (driverType) { case FireFox: default: DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox(); desiredCapabilities.setCapability(CapabilityType.LOGGING_PREFS, logs); // sets the driver to automatically skip download dialog // and save csv,xcel files to a temp directory // that directory is set in the constructor and has a trailing // slash FirefoxProfile firefoxProfile = new FirefoxProfile(); firefoxProfile.setPreference("browser.download.folderList", 2); firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false); String target = this.getTempDownloadPath(); firefoxProfile.setPreference("browser.download.dir", target); firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv,application/vnd.ms-excel"); desiredCapabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile); LOG.debug("creating firefox driver"); driver = new FirefoxDriver(desiredCapabilities); LOG.debug("got firefox driver"); break; case InternetExplorer: break; case Opera: break; case Safari: break; case Chrome: break; } driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS); LOG.debug("driver is loaded via config " + driver.toString()); }
From source file:com.elastica.browserfactory.FirefoxCapabilitiesFactory.java
License:Apache License
protected void configProfile(final FirefoxProfile profile, final DriverConfig webDriverConfig) { profile.setAcceptUntrustedCertificates(webDriverConfig.isSetAcceptUntrustedCertificates()); profile.setAssumeUntrustedCertificateIssuer(webDriverConfig.isSetAssumeUntrustedCertificateIssuer()); if (webDriverConfig.getFirefoxBinPath() != null) { System.setProperty("webdriver.firefox.bin", webDriverConfig.getFirefoxBinPath()); }/*from www. jav a2 s . c o m*/ if (webDriverConfig.getUserAgentOverride() != null) { profile.setPreference("general.useragent.override", webDriverConfig.getUserAgentOverride()); } if (webDriverConfig.getNtlmAuthTrustedUris() != null) { profile.setPreference("network.automatic-ntlm-auth.trusted-uris", webDriverConfig.getNtlmAuthTrustedUris()); } if (webDriverConfig.getBrowserDownloadDir() != null) { profile.setPreference("browser.download.dir", webDriverConfig.getBrowserDownloadDir()); profile.setPreference("browser.download.folderList", 2); profile.setPreference("browser.download.manager.showWhenStarting", false); profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream,text/plain,application/pdf,application/zip,text/csv,text/html"); } if (!webDriverConfig.isEnableJavascript()) { profile.setPreference("javascript.enabled", false); } else { // Add Firefox extension to collect JS Error if (webDriverConfig.isAddJSErrorCollectorExtension()) { try { JavaScriptError.addExtension(profile); } catch (IOException e) { e.printStackTrace(); } } } // fix permission denied issues profile.setPreference("capability.policy.default.Window.QueryInterface", "allAccess"); profile.setPreference("capability.policy.default.Window.frameElement.get", "allAccess"); profile.setPreference("capability.policy.default.HTMLDocument.compatMode.get", "allAccess"); profile.setPreference("capability.policy.default.Document.compatMode.get", "allAccess"); profile.setEnableNativeEvents(false); profile.setPreference("dom.max_chrome_script_run_time", 0); profile.setPreference("dom.max_script_run_time", 0); }
From source file:com.fullteaching.backend.e2e.FirefoxUser.java
License:Apache License
public FirefoxUser(String userName, int timeOfWaitInSeconds) { super(userName, timeOfWaitInSeconds); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("acceptInsecureCerts", true); FirefoxProfile profile = new FirefoxProfile(); // This flag avoids granting the access to the camera profile.setPreference("media.navigator.permission.disabled", true); // This flag force to use fake user media (synthetic video of multiple color) profile.setPreference("media.navigator.streams.fake", true); capabilities.setCapability(FirefoxDriver.PROFILE, profile); String eusApiURL = System.getenv("ET_EUS_API"); if (eusApiURL == null) { this.driver = new FirefoxDriver(capabilities); } else {//ww w . j a v a2 s . c om try { capabilities.setBrowserName("firefox"); this.driver = new RemoteWebDriver(new URL(eusApiURL), capabilities); } catch (MalformedURLException e) { throw new RuntimeException("Exception creaing eusApiURL", e); } } this.driver.manage().timeouts().setScriptTimeout(this.timeOfWaitInSeconds, TimeUnit.SECONDS); this.configureDriver(); }
From source file:com.ggasoftware.uitest.utils.WebDriverWrapper.java
License:Open Source License
/** * initialization FirefoxDriver// w w w. ja v a2 s. c o m */ public static void initFirefoxDriver() { ReporterNGExt.logTechnical("Initialization Firefox Driver"); FirefoxProfile profile = new FirefoxProfile(); profile.setAcceptUntrustedCertificates(true); profile.setAssumeUntrustedCertificateIssuer(true); profile.setEnableNativeEvents(true); profile.setPreference("javascript.enabled", true); profile.setPreference("dom.max_script_run_time", 0); profile.setPreference("dom.max_chrome_script_run_time", 0); setWebDriver(new FirefoxDriver(profile)); setTimeout(TIMEOUT); getDriver().manage().window().maximize(); }
From source file:com.huangyunkun.jviff.service.WebDriverManager.java
License:Apache License
private static WebDriver createWebDriver() { FirefoxProfile firefoxProfile = new FirefoxProfile(); firefoxProfile.setPreference("app.update.auto", false); firefoxProfile.setPreference("app.update.enabled", false); //TODO:Disable proxy first, will add a proxy setting option later firefoxProfile.setPreference("network.proxy.type", 0); WebDriver driver = new FirefoxDriver(firefoxProfile); return driver; }
From source file:com.kurento.kmf.test.client.BrowserClient.java
License:Open Source License
private void initDriver(String hostAddress) { Class<? extends WebDriver> driverClass = browser.getDriverClass(); int hubPort = getProperty("test.hub.port", GridBrowserMediaApiTest.DEFAULT_HUB_PORT); try {// w w w.j ava2s . c om if (driverClass.equals(FirefoxDriver.class)) { FirefoxProfile profile = new FirefoxProfile(); // This flag avoids granting the access to the camera profile.setPreference("media.navigator.permission.disabled", true); if (remoteNode != null) { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(FirefoxDriver.PROFILE, profile); capabilities.setBrowserName(DesiredCapabilities.firefox().getBrowserName()); driver = new RemoteWebDriver(new URL("http://" + hostAddress + ":" + hubPort + "/wd/hub"), capabilities); } else { driver = new FirefoxDriver(profile); } if (!usePhysicalCam && video != null) { launchFakeCam(); } } else if (driverClass.equals(ChromeDriver.class)) { String chromedriver = null; if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_LINUX) { chromedriver = "chromedriver"; } else if (SystemUtils.IS_OS_WINDOWS) { chromedriver = "chromedriver.exe"; } System.setProperty("webdriver.chrome.driver", new File("target/webdriver/" + chromedriver).getAbsolutePath()); ChromeOptions options = new ChromeOptions(); // This flag avoids grant the camera options.addArguments("--use-fake-ui-for-media-stream"); // This flag avoids warning in chrome. See: // https://code.google.com/p/chromedriver/issues/detail?id=799 options.addArguments("--test-type"); if (!usePhysicalCam) { // This flag makes using a synthetic video (green with // spinner) in webrtc. Or it is needed to combine with // use-file-for-fake-video-capture to use a file faking the // cam options.addArguments("--use-fake-device-for-media-stream"); if (video != null) { options.addArguments("--use-file-for-fake-video-capture=" + video); // Alternative: lauch fake cam also in Chrome // launchFakeCam(); } } if (remoteNode != null) { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(ChromeOptions.CAPABILITY, options); capabilities.setBrowserName(DesiredCapabilities.chrome().getBrowserName()); driver = new RemoteWebDriver(new URL("http://" + hostAddress + ":" + hubPort + "/wd/hub"), capabilities); } else { driver = new ChromeDriver(options); } } driver.manage().timeouts().setScriptTimeout(timeout, TimeUnit.SECONDS); } catch (MalformedURLException e) { log.error("MalformedURLException in BrowserClient.initDriver", e); } }
From source file:com.lazerycode.ebselen.EbselenCore.java
License:Apache License
/** * Configure the FireFox profile if using FireFox Driver * * @return FirefoxProfile/*from www .j av a2s. c om*/ */ private FirefoxProfile generateFirefoxProfile() { FirefoxProfile prf = new FirefoxProfile(); prf.setPreference("dom.max_chrome_script_run_time", 60); prf.setPreference("setTimeoutInSeconds", 60); prf.setPreference("dom.max_script_run_time", 60); prf.setPreference("dom.popup_maximum", 0); prf.setPreference("privacy.popups.disable_from_plugins", 3); prf.setPreference("browser.xul.error_pages.enabled", false); prf.setPreference("general.useragent.extra.firefox", "Firefox"); prf.setAcceptUntrustedCertificates(true); return (prf); }
From source file:com.liferay.cucumber.selenium.WebDriverUtil.java
License:Open Source License
private WebDriver _getFirefoxDriver() { FirefoxProfile firefoxProfile = new FirefoxProfile(); firefoxProfile.setPreference("browser.download.folderList", 2); firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false); firefoxProfile.setPreference("browser.download.useDownloadDir", true); firefoxProfile.setPreference("browser.helperApps.alwaysAsk.force", false); firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/excel,application/msword,application/pdf," + "application/zip,audio/mpeg3,image/jpeg,image/png,text/plain"); firefoxProfile.setPreference("dom.max_chrome_script_run_time", 300); firefoxProfile.setPreference("dom.max_script_run_time", 300); if (Validator.isNotNull(PropsValues.BROWSER_FIREFOX_BIN_FILE)) { File file = new File(PropsValues.BROWSER_FIREFOX_BIN_FILE); FirefoxBinary firefoxBinary = new FirefoxBinary(file); return new FirefoxDriver(firefoxBinary, firefoxProfile); } else {/*from w w w. ja v a 2 s. c om*/ return new FirefoxDriver(firefoxProfile); } }
From source file:com.liferay.faces.test.selenium.browser.internal.BrowserDriverFactoryImpl.java
License:Open Source License
@Override public BrowserDriver getBrowserDriverImplementation(String browserName, boolean browserHeadless, boolean browserSimulateMobile) { WebDriver webDriver;// w w w . ja va 2s.c om if ("chrome".equals(browserName)) { ChromeOptions chromeOptions = new ChromeOptions(); String chromeBinaryPath = TestUtil.getSystemPropertyOrDefault("webdriver.chrome.bin", null); if (chromeBinaryPath != null) { chromeOptions.setBinary(chromeBinaryPath); logger.info("Chrome Binary: {}", chromeBinaryPath); } if (browserHeadless) { // The start-maximized argument does not work correctly in headless mode, so set the window size to // 1920x1200 (resolution of a 15.4 inch screen). chromeOptions.addArguments("headless", "disable-gpu", "window-size=1920,1200"); } else { chromeOptions.addArguments("start-maximized"); } if (browserSimulateMobile) { chromeOptions.addArguments("user-agent=\"" + IPHONE_7_IOS_10_0_USER_AGENT + "\""); } webDriver = new ChromeDriver(chromeOptions); } else if ("firefox".equals(browserName)) { // The value of this property is obtained automatically by FirefoxDriver. String firefoxBinaryPath = TestUtil.getSystemPropertyOrDefault("webdriver.firefox.bin", null); if (firefoxBinaryPath != null) { logger.info("Firefox Binary: {}", firefoxBinaryPath); } FirefoxProfile firefoxProfile = new FirefoxProfile(); if (browserHeadless) { throw new UnsupportedOperationException("Headless mode is not yet supported for Firefox"); } if (browserSimulateMobile) { firefoxProfile.setPreference("general.useragent.override", IPHONE_7_IOS_10_0_USER_AGENT); } webDriver = new FirefoxDriver(firefoxProfile); } else if ("phantomjs".equals(browserName)) { // The value of this property is obtained automatically by PhantomJSDriver. String phantomJSBinaryPath = TestUtil.getSystemPropertyOrDefault("phantomjs.binary.path", null); if (phantomJSBinaryPath != null) { logger.info("PhantomJS Binary: {}", phantomJSBinaryPath); } DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); if (!browserHeadless) { throw new UnsupportedOperationException("Non-headless mode is not yet supported for PhantomJS"); } if (browserSimulateMobile) { desiredCapabilities.setCapability( PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX + "userAgent", IPHONE_7_IOS_10_0_USER_AGENT); desiredCapabilities.setCapability( PhantomJSDriverService.PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX + "User-Agent", IPHONE_7_IOS_10_0_USER_AGENT); } // Set the Accept-Language header to "en-US,en;q=0.8" to ensure that it isn't set to "en-US," (the default). desiredCapabilities.setCapability( PhantomJSDriverService.PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX + "Accept-Language", "en-US,en;q=0.8"); String phantomJSLogLevel; if (logger.isDebugEnabled()) { phantomJSLogLevel = "DEBUG"; } else if (logger.isInfoEnabled()) { phantomJSLogLevel = "INFO"; } else if (logger.isWarnEnabled()) { phantomJSLogLevel = "WARN"; } else if (logger.isErrorEnabled()) { phantomJSLogLevel = "ERROR"; } else { phantomJSLogLevel = "NONE"; } String[] phantomArgs = new String[1]; phantomArgs[0] = "--webdriver-loglevel=" + phantomJSLogLevel; desiredCapabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, phantomArgs); webDriver = new PhantomJSDriver(desiredCapabilities); } else if ("htmlunit".equals(browserName)) { if (!browserHeadless) { throw new UnsupportedOperationException("Non-headless mode is not yet supported for HtmlUnit"); } if (browserSimulateMobile) { webDriver = new HtmlUnitDriverLiferayFacesImpl(IPHONE_7_IOS_10_0_USER_AGENT); } else { webDriver = new HtmlUnitDriverLiferayFacesImpl(); } } else if ("jbrowser".equals(browserName)) { if (!browserHeadless) { throw new UnsupportedOperationException("Non-headless mode is not yet supported for JBrowser"); } if (browserSimulateMobile) { throw new UnsupportedOperationException("Mobile simulation is not yet supported for JBrowser."); } webDriver = new JBrowserDriver(); } else { throw new UnsupportedOperationException("Browser with not supported: " + browserName); } if (!"chrome".equals(browserName)) { webDriver.manage().window().maximize(); } return getBrowserDriverImplementation(webDriver, browserHeadless, browserSimulateMobile); }
From source file:com.lohika.alp.selenium.configurator.FirefoxDriverConfigurator.java
License:Open Source License
public DesiredCapabilities configure(DesiredCapabilities capabilities) { String[] domains = JsErrorCatcherConfiguration.getInstance().getAllowDomains(); if (domains == null) return capabilities; FirefoxProfile profile; profile = (FirefoxProfile) capabilities.getCapability(FirefoxDriver.PROFILE); if (profile == null) profile = new FirefoxProfile(); // enable access to XPCComponents profile.setPreference("signed.applets.codebase_principal_support", true); int i = 0;/* w w w. j a v a2s . c o m*/ for (String host : domains) { profile.setPreference("capability.principal.codebase.p" + i + ".granted", "UniversalXPConnect UniversalBrowserRead UniversalBrowserWrite UniversalPreferencesRead UniversalPreferencesWrite UniversalFileRead"); profile.setPreference("capability.principal.codebase.p" + i + ".id", host); i++; } capabilities.setCapability(FirefoxDriver.PROFILE, profile); return capabilities; }