List of usage examples for org.openqa.selenium.firefox FirefoxProfile setPreference
public void setPreference(String key, Object value)
From source file:org.alfresco.grid.WebDriverFactory.java
License:Open Source License
/** * Create a basic fire fox profile.// w ww . j a v a2 s .c om * @return {@link FirefoxProfile} */ private FirefoxProfile createProfile(String... profile) { FirefoxProfile firefoxProfile = null; if (profile.length > 0) { firefoxProfile = new ProfilesIni().getProfile(profile[0]); if (firefoxProfile == null) { throw new RuntimeException("The following profile: %s can not be found"); } } else { firefoxProfile = new FirefoxProfile(); } //Change default retry timeout of 30 minutes to 2 minutes firefoxProfile.setPreference("dom.mms.retrievalRetryIntervals;", "60000,120000"); //Set it to not store session history, reduced memory foot print. firefoxProfile.setPreference("browser.sessionhistory.max_total_viewers;", "0"); firefoxProfile.setPreference("intl.accept_languages", language); firefoxProfile.setPreference("general.useragent.locale", locale); return firefoxProfile; }
From source file:org.alfresco.grid.WebDriverFactory.java
License:Open Source License
/** * Creates a new instance of an {@link FirefoxDriver} * @param boolean with a specific profile or false for default FireFox * @return {@link DesiredCapabilities} type of browser capability * @throws UnsupportedOperationException if grid url is invalid *//*from w ww .j a va 2s .c o m*/ private FirefoxDriver getFireFox(boolean customProfile) { DesiredCapabilities capabilities = DesiredCapabilities.firefox(); FirefoxProfile firefoxProfile = createProfile(); //The below two preferences added to disable the firefox auto update firefoxProfile.setPreference("app.update.auto", false); firefoxProfile.setPreference("app.update.enabled", false); firefoxProfile.setEnableNativeEvents(true); if (customProfile) { firefoxProfile.setPreference("browser.download.folderList", 2); firefoxProfile.setPreference("browser.download.dir", downloadDirectory); firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", mimeTypes); } if (preferences != null && preferences.size() > 0) { Set<BrowserPreference> preferenceSet = preferences.keySet(); for (BrowserPreference browserPreference : preferenceSet) { if (BrowserPreference.Language.equals(browserPreference)) { firefoxProfile.setPreference(browserPreference.getFireFoxKey(), formatLocale((Locale) preferences.get(browserPreference))); } else { if (BrowserPreference.DownloadFolderList.equals(browserPreference)) { firefoxProfile.setPreference(browserPreference.getFireFoxKey(), Integer.valueOf((String) preferences.get(browserPreference))); } else { firefoxProfile.setPreference(browserPreference.getFireFoxKey(), (String) preferences.get(browserPreference)); } } } } capabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile); return new FirefoxDriver(capabilities); }
From source file:org.apache.falcon.regression.testHelper.BaseUITestClass.java
License:Apache License
protected static void openBrowser() { FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("network.negotiate-auth.trusted-uris", MerlinConstants.PRISM_URL); driver = new FirefoxDriver(profile); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); int width = Config.getInt("browser.window.width", 0); int height = Config.getInt("browser.window.height", 0); if (width * height == 0) { driver.manage().window().maximize(); } else {/*from w ww.j a v a 2s . c om*/ driver.manage().window().setPosition(new Point(0, 0)); driver.manage().window().setSize(new Dimension(width, height)); } }
From source file:org.apache.nutch.protocol.webdriver.HttpWebClient.java
License:Apache License
public static String getHtmlPage(String url, Configuration conf) { WebDriver driver = null;//from w w w .j a va2 s . c o m try { FirefoxProfile profile = new FirefoxProfile(); String proxyHost = conf.get("http.proxy.host"); int proxyPort = conf.getInt("http.proxy.port", 8080); if (proxyHost != null && proxyHost.length() > 0) { profile.setPreference("network.proxy.type", 1); profile.setPreference("network.proxy.http", proxyHost); profile.setPreference("network.proxy.http_port", proxyPort); } DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability("marionette", true); capabilities.setCapability("firefox_profile", profile); int driverServicePort = conf.getInt("webdriver.service.port", 4444); DriverService ds = NutchDriverService.createDriverService(driverServicePort); driver = new NutchFirefoxDriver(ds, capabilities); driver.get(url); // Wait for the page to load, timeout after 3 seconds new WebDriverWait(driver, 3); // Extract body String innerHtml = driver.findElement(By.tagName("body")).getAttribute("innerHTML"); return innerHtml; // I'm sure this catch statement is a code smell ; borrowing it from // lib-htmlunit } catch (Exception e) { throw new RuntimeException(e); } finally { if (driver != null) try { driver.quit(); } catch (Exception e) { throw new RuntimeException(e); } } }
From source file:org.apache.openmeetings.test.selenium.AbstractTestDefaults.java
License:Apache License
@Before public void setUp() throws Exception { FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("intl.accept_languages", getLocale()); driver = new FirefoxDriver(profile); }
From source file:org.apache.roller.selenium.InitialLoginTestIT.java
License:Apache License
@Before public void setUp() throws Exception { FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("intl.accept_languages", "en_US"); driver = new FirefoxDriver(profile); baseUrl = "http://localhost:8080/roller/"; driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); }
From source file:org.apache.zeppelin.WebDriverManager.java
License:Apache License
public static WebDriver getWebDriver() { WebDriver driver = null;/*from w ww . j a va 2s.com*/ if (driver == null) { try { FirefoxBinary ffox = new FirefoxBinary(); if ("true".equals(System.getenv("TRAVIS"))) { ffox.setEnvironmentProperty("DISPLAY", ":99"); // xvfb is supposed to // run with DISPLAY 99 } int firefoxVersion = WebDriverManager.getFirefoxVersion(); LOG.info("Firefox version " + firefoxVersion + " detected"); downLoadsDir = FileUtils.getTempDirectory().toString(); String tempPath = downLoadsDir + "/firefox/"; downloadGeekoDriver(firefoxVersion, tempPath); FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("browser.download.folderList", 2); profile.setPreference("browser.download.dir", downLoadsDir); profile.setPreference("browser.helperApps.alwaysAsk.force", false); profile.setPreference("browser.download.manager.showWhenStarting", false); profile.setPreference("browser.download.manager.showAlertOnComplete", false); profile.setPreference("browser.download.manager.closeWhenDone", true); profile.setPreference("app.update.auto", false); profile.setPreference("app.update.enabled", false); profile.setPreference("dom.max_script_run_time", 0); profile.setPreference("dom.max_chrome_script_run_time", 0); profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/x-ustar,application/octet-stream,application/zip,text/csv,text/plain"); profile.setPreference("network.proxy.type", 0); System.setProperty(GeckoDriverService.GECKO_DRIVER_EXE_PROPERTY, tempPath + "geckodriver"); System.setProperty(SystemProperty.DRIVER_USE_MARIONETTE, "false"); FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.setBinary(ffox); firefoxOptions.setProfile(profile); driver = new FirefoxDriver(firefoxOptions); } catch (Exception e) { LOG.error("Exception in WebDriverManager while FireFox Driver ", e); } } if (driver == null) { try { driver = new ChromeDriver(); } catch (Exception e) { LOG.error("Exception in WebDriverManager while ChromeDriver ", e); } } if (driver == null) { try { driver = new SafariDriver(); } catch (Exception e) { LOG.error("Exception in WebDriverManager while SafariDriver ", e); } } String url; if (System.getenv("url") != null) { url = System.getenv("url"); } else { url = "http://localhost:8080"; } long start = System.currentTimeMillis(); boolean loaded = false; driver.manage().timeouts().implicitlyWait(AbstractZeppelinIT.MAX_IMPLICIT_WAIT, TimeUnit.SECONDS); driver.get(url); while (System.currentTimeMillis() - start < 60 * 1000) { // wait for page load try { (new WebDriverWait(driver, 30)).until(new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver d) { return d.findElement(By.xpath("//i[@uib-tooltip='WebSocket Connected']")).isDisplayed(); } }); loaded = true; break; } catch (TimeoutException e) { LOG.info("Exception in WebDriverManager while WebDriverWait ", e); driver.navigate().to(url); } } if (loaded == false) { fail(); } driver.manage().window().maximize(); return driver; }
From source file:org.asqatasun.sebuilder.tools.ProfileFactory.java
License:Open Source License
/** * //from ww w . j a v a2 s. c o m * @param firefoxProfile */ private void setUpPreferences(FirefoxProfile firefoxProfile, boolean loadImage) { // to have a blank page on start-up firefoxProfile.setPreference("browser.startup.page", 0); firefoxProfile.setPreference("browser.cache.disk.capacity", 0); firefoxProfile.setPreference("browser.cache.disk.enable", false); firefoxProfile.setPreference("browser.cache.disk.smart_size.enabled", false); firefoxProfile.setPreference("browser.cache.disk.smart_size.first_run", false); firefoxProfile.setPreference("browser.cache.disk.smart_size_cached_value", 0); firefoxProfile.setPreference("browser.cache.memory.enable", false); firefoxProfile.setPreference("browser.shell.checkDefaultBrowser", false); firefoxProfile.setPreference("browser.startup.homepage_override.mstone", "ignore"); firefoxProfile.setPreference("browser.preferences.advanced.selectedTabIndex", 0); firefoxProfile.setPreference("browser.privatebrowsing.autostart", false); firefoxProfile.setPreference("browser.link.open_newwindow", 2); firefoxProfile.setPreference("Network.cookie.cookieBehavior", 1); firefoxProfile.setPreference("signon.autologin.proxy", true); // to disable the update of search engines firefoxProfile.setPreference("browser.search.update", false); if (loadImage) { // To enable the load of images firefoxProfile.setPreference("permissions.default.image", 1); } else { // To disable the load of images firefoxProfile.setPreference("permissions.default.image", 2); } }
From source file:org.asqatasun.sebuilder.tools.ProfileFactory.java
License:Open Source License
/** * Add entension /* w w w . j a v a2s .c om*/ * @param firefoxProfile */ private void setUpExtensions(FirefoxProfile firefoxProfile) { for (String extensionPath : extensionPathList) { try { firefoxProfile.addExtension(new File(extensionPath)); } catch (IOException ex) { Logger.getLogger(this.getClass()).error(ex); } } //---------------------------------------------------------------------- // Firebug options //---------------------------------------------------------------------- firefoxProfile.setPreference("extensions.firebug.allPagesActivation", "on"); firefoxProfile.setPreference("extensions.firebug.defaultPanelName", "net"); firefoxProfile.setPreference("extensions.firebug.net.enableSites", true); firefoxProfile.setPreference("extensions.firebug.script.enableSites", true); firefoxProfile.setPreference("extensions.firebug.onByDefault", true); firefoxProfile.setPreference("extensions.firebug.currentVersion", firebugVersion); //---------------------------------------------------------------------- //---------------------------------------------------------------------- // NetExport options //---------------------------------------------------------------------- // Auto export feature is enabled by default. firefoxProfile.setPreference("extensions.firebug.netexport.alwaysEnableAutoExport", true); // Auto export feature stores results into a local file firefoxProfile.setPreference("extensions.firebug.netexport.autoExportToFile", true); // Auto export feature sends results to the server (default is false) firefoxProfile.setPreference("extensions.firebug.netexport.autoExportToServer", false); // Show preview of exported data by default. firefoxProfile.setPreference("extensions.firebug.netexport.showPreview", false); // Displaye confirmation before uploading collecetd data to the server yes/no. firefoxProfile.setPreference("extensions.firebug.netexport.sendToConfirmation", false); // Number of milliseconds to wait after the last page request to declare the page loaded. // We don't wast time // firefoxProfile.setPreference("extensions.firebug.netexport.pageLoadedTimeout", pageLoadedTimeout); // Number of milliseconds to wait after the page is exported even if not loaded yet. // Set to zero to switch off this feature. // firefoxProfile.setPreference("extensions.firebug.netexport.timeout", timeout); // firefoxProfile.setPreference("extensions.firebug.netexport.Automation", true); // Default log directory for auto-exported HAR files. firefoxProfile.setPreference("extensions.firebug.netexport.defaultLogDir", createRandomNetExportPath(firefoxProfile)); }
From source file:org.cerberus.engine.execution.impl.SeleniumServerService.java
License:Open Source License
/** * Instanciate DesiredCapabilities regarding the browser * @param capabilities/*from w w w . j a v a2 s. c o m*/ * @param browser * @param tCExecution * @return * @throws CerberusException */ private DesiredCapabilities setCapabilityBrowser(DesiredCapabilities capabilities, String browser, TestCaseExecution tCExecution) throws CerberusException { try { if (browser.equalsIgnoreCase("firefox")) { capabilities = DesiredCapabilities.firefox(); FirefoxProfile profile = new FirefoxProfile(); profile.setAcceptUntrustedCertificates(true); profile.setAssumeUntrustedCertificateIssuer(true); profile.setPreference("app.update.enabled", false); profile.setEnableNativeEvents(true); try { Invariant invariant = this.invariantService.findInvariantByIdValue("COUNTRY", tCExecution.getCountry()); if (invariant.getGp2() == null) { LOG.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) { LOG.warn("Country selected (" + tCExecution.getCountry() + ") not in Invariant table, default language set to English (en)"); profile.setPreference("intl.accept_languages", "en"); } capabilities.setCapability("acceptInsecureCerts", true); capabilities.setCapability("acceptSslCerts", true); //capabilities.setCapability("marionette", true); capabilities.setCapability(FirefoxDriver.PROFILE, profile); } else if (browser.equalsIgnoreCase("IE")) { capabilities = DesiredCapabilities.internetExplorer(); } else if (browser.equalsIgnoreCase("chrome")) { capabilities = DesiredCapabilities.chrome(); } else if (browser.contains("android")) { capabilities = DesiredCapabilities.android(); } else if (browser.contains("ipad")) { capabilities = DesiredCapabilities.ipad(); } else if (browser.contains("iphone")) { capabilities = DesiredCapabilities.iphone(); } else if (browser.contains("opera")) { capabilities = DesiredCapabilities.opera(); } else if (browser.contains("safari")) { capabilities = DesiredCapabilities.safari(); } else { LOG.warn("Not supported Browser : " + browser); MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM); mes.setDescription( mes.getDescription().replace("%MES%", "Browser '" + browser + "' is not supported")); mes.setDescription("Not supported Browser : " + browser); throw new CerberusException(mes); } } catch (CerberusException ex) { MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM); mes.setDescription(mes.getDescription().replace("%MES%", "Failed to set capability on the browser '" + browser + "' due to " + ex.getMessageError().getDescription())); throw new CerberusException(mes); } return capabilities; }