List of usage examples for org.openqa.selenium.firefox FirefoxProfile setPreference
public void setPreference(String key, Object value)
From source file:org.kitodo.selenium.testframework.Browser.java
License:Open Source License
private static void provideGeckoDriver() throws IOException { String driverFileName = "geckodriver"; if (SystemUtils.IS_OS_WINDOWS) { driverFileName = driverFileName.concat(".exe"); }//from ww w. j a v a 2s.co m File driverFile = new File(DRIVER_DIR + driverFileName); if (!driverFile.exists()) { WebDriverProvider.provideGeckoDriver(GECKO_DRIVER_VERSION, DOWNLOAD_DIR, DRIVER_DIR); } FirefoxProfile profile = new FirefoxProfile(); profile.setAssumeUntrustedCertificateIssuer(false); profile.setPreference("browser.helperApps.alwaysAsk.force", false); profile.setPreference("browser.download.dir", DOWNLOAD_DIR); FirefoxOptions options = new FirefoxOptions(); options.setProfile(profile); webDriver = new FirefoxDriver(options); }
From source file:org.kuali.rice.testtools.selenium.JenkinsJsonJobResultsBase.java
License:Educational Community License
public void setUp() throws MalformedURLException, InterruptedException { if (System.getProperty(JENKINS_JOBS) == null) { System.out.println("Don't know what jobs to retrieve. -D" + JENKINS_JOBS + "= must be declared."); System.exit(1);//from w w w. j a va 2 s . co m } jenkinsBase = System.getProperty(JENKINS_BASE_URL, "http://ci.kuali.org"); outputDirectory = System.getProperty(JSON_OUTPUT_DIR); FirefoxProfile profile = new FirefoxProfile(); profile.setEnableNativeEvents(false); downloadDir = System.getProperty(BROWSER_DOWNLOAD_DIR, System.getProperty("user.home") + File.separator + "Downloads"); // download files automatically (don't prompt) profile.setPreference("browser.download.folderList", 2); profile.setPreference("browser.download.manager.showWhenStarting", false); profile.setPreference("browser.download.dir", downloadDir); profile.setPreference(BROWSER_HELPER_APPS_NEVER_ASK_SAVE_TO_DISK, System.getProperty(BROWSER_HELPER_APPS_NEVER_ASK_SAVE_TO_DISK, "application/zip")); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(FirefoxDriver.PROFILE, profile); driver = new FirefoxDriver(capabilities); driver.manage().timeouts().implicitlyWait(WebDriverUtils.configuredImplicityWait(), TimeUnit.SECONDS); driver.get(jenkinsBase + "/login?form"); // CAS // WebDriverUtils.waitFor(driver, WebDriverUtils.configuredImplicityWait(), By.id("username"), // this.getClass().toString()); // driver.findElement(By.id("username")).sendKeys(System.getProperty(CAS_USERNAME)); // driver.findElement(By.id("password")).sendKeys(System.getProperty(CAS_PASSWORD)); // driver.findElement(By.name("submit")).click(); // Thread.sleep(1000); // // exitOnLoginProblems(); // Jenkins login page (don't login, we have authenticated through CAS already WebDriverUtils.waitFor(driver, WebDriverUtils.configuredImplicityWait(), By.xpath("//span[contains(text(), 'Page generated')]"), this.getClass().toString()); // setup jobs builds jobsBuildsStrings = System.getProperty(JENKINS_JOBS).split("[,\\s]"); String job; for (String jobsBuildsString : jobsBuildsStrings) { if (jobsBuildsString.contains(":")) { List<String> jobBuilds = Arrays.asList(jobsBuildsString.split(":")); job = jobBuilds.get(0); // first item is the job name jobs.add(job); if (jobBuilds.size() == 2 && "all".equals(jobBuilds.get(1))) { // job:all jobsBuildsMap.put(job, fetchAllJobNumbers(job)); } else { // regular usage jobsBuildsMap.put(job, jobBuilds.subList(1, jobBuilds.size())); // first item is the job name } } else { // no jobNumbers specified, use last complete build number List<String> jobBuilds = new LinkedList<String>(); jobBuilds.add(fetchLastCompletedBuildNumber(jobsBuildsString) + ""); jobs.add(jobsBuildsString); jobsBuildsMap.put(jobsBuildsString, jobBuilds); } } passed = true; }
From source file:org.kurento.test.browser.Browser.java
License:Apache License
private void createFirefoxBrowser(DesiredCapabilities capabilities) throws MalformedURLException { FirefoxProfile profile = new FirefoxProfile(); // This flag avoids granting the access to the camera profile.setPreference("media.navigator.permission.disabled", true); capabilities.setCapability(FirefoxDriver.PROFILE, profile); capabilities.setBrowserName(DesiredCapabilities.firefox().getBrowserName()); // Firefox extensions if (extensions != null && !extensions.isEmpty()) { for (Map<String, String> extension : extensions) { InputStream is = getExtensionAsInputStream(extension.values().iterator().next()); if (is != null) { try { File xpi = File.createTempFile(extension.keySet().iterator().next(), ".xpi"); FileUtils.copyInputStreamToFile(is, xpi); profile.addExtension(xpi); } catch (Throwable t) { log.error("Error loading Firefox extension {} ({} : {})", extension, t.getClass(), t.getMessage()); }/* ww w .j a v a2 s .c om*/ } } } createDriver(capabilities, profile); }
From source file:org.kurento.test.client.BrowserClient.java
License:Open Source License
public void init() { Class<? extends WebDriver> driverClass = browserType.getDriverClass(); try {//from w w w. ja v a 2 s.c o m DesiredCapabilities capabilities = new DesiredCapabilities(); 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); capabilities.setCapability(FirefoxDriver.PROFILE, profile); capabilities.setBrowserName(DesiredCapabilities.firefox().getBrowserName()); // Firefox extensions if (extensions != null && !extensions.isEmpty()) { for (Map<String, String> extension : extensions) { InputStream is = getExtensionAsInputStream(extension.values().iterator().next()); if (is != null) { try { File xpi = File.createTempFile(extension.keySet().iterator().next(), ".xpi"); FileUtils.copyInputStreamToFile(is, xpi); profile.addExtension(xpi); } catch (Throwable t) { log.error("Error loading Firefox extension {} ({} : {})", extension, t.getClass(), t.getMessage()); } } } } if (scope == BrowserScope.SAUCELABS) { createSaucelabsDriver(capabilities); } else if (scope == BrowserScope.REMOTE) { createRemoteDriver(capabilities); } else { driver = new FirefoxDriver(profile); } } else if (driverClass.equals(ChromeDriver.class)) { // Chrome driver ChromeDriverManager.getInstance().setup(); // Chrome options ChromeOptions options = new ChromeOptions(); // Chrome extensions if (extensions != null && !extensions.isEmpty()) { for (Map<String, String> extension : extensions) { InputStream is = getExtensionAsInputStream(extension.values().iterator().next()); if (is != null) { try { File crx = File.createTempFile(extension.keySet().iterator().next(), ".crx"); FileUtils.copyInputStreamToFile(is, crx); options.addExtensions(crx); } catch (Throwable t) { log.error("Error loading Chrome extension {} ({} : {})", extension, t.getClass(), t.getMessage()); } } } } if (enableScreenCapture) { // This flag enables the screen sharing options.addArguments("--enable-usermedia-screen-capturing"); String windowTitle = TEST_SCREEN_SHARE_TITLE_DEFAULT; if (platform != null && (platform == Platform.WINDOWS || platform == Platform.XP || platform == Platform.VISTA || platform == Platform.WIN8 || platform == Platform.WIN8_1)) { windowTitle = TEST_SCREEN_SHARE_TITLE_DEFAULT_WIN; } options.addArguments("--auto-select-desktop-capture-source=" + getProperty(TEST_SCREEN_SHARE_TITLE_PROPERTY, windowTitle)); } else { // 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 (protocol == Protocol.FILE) { // This flag allows reading local files in video tags options.addArguments("--allow-file-access-from-files"); } 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 && isLocal()) { options.addArguments("--use-file-for-fake-video-capture=" + video); } } capabilities.setCapability(ChromeOptions.CAPABILITY, options); capabilities.setBrowserName(DesiredCapabilities.chrome().getBrowserName()); if (scope == BrowserScope.SAUCELABS) { createSaucelabsDriver(capabilities); } else if (scope == BrowserScope.REMOTE) { createRemoteDriver(capabilities); } else { driver = new ChromeDriver(options); } } else if (driverClass.equals(InternetExplorerDriver.class)) { if (scope == BrowserScope.SAUCELABS) { capabilities.setBrowserName(DesiredCapabilities.internetExplorer().getBrowserName()); capabilities.setCapability("ignoreProtectedModeSettings", true); createSaucelabsDriver(capabilities); } } else if (driverClass.equals(SafariDriver.class)) { if (scope == BrowserScope.SAUCELABS) { capabilities.setBrowserName(DesiredCapabilities.safari().getBrowserName()); createSaucelabsDriver(capabilities); } } // Timeouts changeTimeout(timeout); if (protocol == Protocol.FILE) { String clientPage = client.toString(); File clientPageFile = new File( this.getClass().getClassLoader().getResource("static" + clientPage).getFile()); url = protocol.toString() + clientPageFile.getAbsolutePath(); } else { String hostName = host != null ? host : node; url = protocol.toString() + hostName + ":" + serverPort + client.toString(); } log.info("*** Browsing URL with WebDriver: {}", url); driver.get(url); } catch (MalformedURLException e) { log.error("MalformedURLException in BrowserClient.initDriver", e); } // startPing(); }
From source file:org.nuxeo.functionaltests.AbstractTest.java
License:Open Source License
protected static void initFirefoxDriver() throws Exception { DesiredCapabilities dc = DesiredCapabilities.firefox(); FirefoxProfile profile = new FirefoxProfile(); // Disable native events (makes things break on Windows) profile.setEnableNativeEvents(false); // Set English as default language profile.setPreference("general.useragent.locale", "en"); profile.setPreference("intl.accept_languages", "en"); // Set other confs to speed up FF // Speed up firefox by pipelining requests on a single connection profile.setPreference("network.http.keep-alive", true); profile.setPreference("network.http.pipelining", true); profile.setPreference("network.http.proxy.pipelining", true); profile.setPreference("network.http.pipelining.maxrequests", 8); // Try to use less memory profile.setPreference("browser.sessionhistory.max_entries", 10); profile.setPreference("browser.sessionhistory.max_total_viewers", 4); profile.setPreference("browser.sessionstore.max_tabs_undo", 4); profile.setPreference("browser.sessionstore.interval", 1800000); // do not load images profile.setPreference("permissions.default.image", 2); // disable unresponsive script alerts profile.setPreference("dom.max_script_run_time", 0); profile.setPreference("dom.max_chrome_script_run_time", 0); // don't skip proxy for localhost profile.setPreference("network.proxy.no_proxies_on", ""); // prevent different kinds of popups/alerts profile.setPreference("browser.tabs.warnOnClose", false); profile.setPreference("browser.tabs.warnOnOpen", false); profile.setPreference("extensions.newAddons", false); profile.setPreference("extensions.update.notifyUser", false); // disable autoscrolling profile.setPreference("browser.urlbar.autocomplete.enabled", false); // downloads conf profile.setPreference("browser.download.useDownloadDir", false); // prevent FF from running in offline mode when there's no network // connection profile.setPreference("toolkit.networkmanager.disable", true); // prevent FF from giving health reports profile.setPreference("datareporting.policy.dataSubmissionEnabled", false); profile.setPreference("datareporting.healthreport.uploadEnabled", false); profile.setPreference("datareporting.healthreport.service.firstRun", false); profile.setPreference("datareporting.healthreport.service.enabled", false); profile.setPreference("datareporting.healthreport.logging.consoleEnabled", false); // start page conf to speed up FF profile.setPreference("browser.startup.homepage", "about:blank"); profile.setPreference("pref.browser.homepage.disable_button.bookmark_page", false); profile.setPreference("pref.browser.homepage.disable_button.restore_default", false); // misc confs to avoid useless updates profile.setPreference("browser.search.update", false); profile.setPreference("browser.bookmarks.restore_default_bookmarks", false); // misc confs to speed up FF profile.setPreference("extensions.ui.dictionary.hidden", true); profile.setPreference("layout.spellcheckDefault", 0); addFireBug(profile);//w ww. j a v a2s . c om Proxy proxy = startProxy(); if (proxy != null) { // Does not work, but leave code for when it does // Workaround: use 127.0.0.2 proxy.setNoProxy(""); profile.setProxyPreferences(proxy); } dc.setCapability(FirefoxDriver.PROFILE, profile); driver = new FirefoxDriver(dc); }
From source file:org.nuxeo.functionaltests.AbstractTest.java
License:Open Source License
protected static void addFireBug(FirefoxProfile profile) throws Exception { // this is preventing from running tests in eclipse // profile.addExtension(AbstractTest.class, "/firebug.xpi"); File xpi = null;/*from w w w . j av a 2 s . c om*/ List<String> clf = getClassLoaderFiles(); for (String f : clf) { if (f.endsWith("/" + FIREBUG_XPI)) { xpi = new File(f); } } if (xpi == null) { String customM2Repo = System.getProperty("M2_REPO", M2_REPO).replaceAll("/$", ""); // try to guess the location in the M2 repo for (String f : clf) { if (f.contains(customM2Repo)) { String m2 = f.substring(0, f.indexOf(customM2Repo) + customM2Repo.length()); xpi = new File(m2 + "/" + FIREBUG_M2 + "/" + FIREBUG_XPI); break; } } } if (xpi == null || !xpi.exists()) { log.warn(FIREBUG_XPI + " not found in classloader or local M2 repository"); return; } profile.addExtension(xpi); // avoid "first run" page profile.setPreference("extensions.firebug.currentVersion", FIREBUG_VERSION); }
From source file:org.nuxeo.functionaltests.drivers.FirefoxDriverProvider.java
License:Open Source License
public static FirefoxProfile getProfile() throws Exception { FirefoxProfile profile = new FirefoxProfile(); // Disable native events (makes things break on Windows) profile.setEnableNativeEvents(false); // Set English as default language profile.setPreference("general.useragent.locale", "en"); profile.setPreference("intl.accept_languages", "en"); // Set other confs to speed up FF // Speed up firefox by pipelining requests on a single connection profile.setPreference("network.http.keep-alive", true); profile.setPreference("network.http.pipelining", true); profile.setPreference("network.http.proxy.pipelining", true); profile.setPreference("network.http.pipelining.maxrequests", 8); // Try to use less memory profile.setPreference("browser.sessionhistory.max_entries", 10); profile.setPreference("browser.sessionhistory.max_total_viewers", 4); profile.setPreference("browser.sessionstore.max_tabs_undo", 4); profile.setPreference("browser.sessionstore.interval", 1800000); // disable unresponsive script alerts profile.setPreference("dom.max_script_run_time", 0); profile.setPreference("dom.max_chrome_script_run_time", 0); // don't skip proxy for localhost profile.setPreference("network.proxy.no_proxies_on", ""); // prevent different kinds of popups/alerts profile.setPreference("browser.tabs.warnOnClose", false); profile.setPreference("browser.tabs.warnOnOpen", false); profile.setPreference("extensions.newAddons", false); profile.setPreference("extensions.update.notifyUser", false); // disable autoscrolling profile.setPreference("browser.urlbar.autocomplete.enabled", false); // downloads conf profile.setPreference("browser.download.useDownloadDir", false); // prevent FF from running in offline mode when there's no network // connection profile.setPreference("toolkit.networkmanager.disable", true); // prevent FF from giving health reports profile.setPreference("datareporting.policy.dataSubmissionEnabled", false); profile.setPreference("datareporting.healthreport.uploadEnabled", false); profile.setPreference("datareporting.healthreport.service.firstRun", false); profile.setPreference("datareporting.healthreport.service.enabled", false); profile.setPreference("datareporting.healthreport.logging.consoleEnabled", false); // start page conf to speed up FF profile.setPreference("browser.startup.homepage", "about:blank"); profile.setPreference("pref.browser.homepage.disable_button.bookmark_page", false); profile.setPreference("pref.browser.homepage.disable_button.restore_default", false); // misc confs to avoid useless updates profile.setPreference("browser.search.update", false); profile.setPreference("browser.bookmarks.restore_default_bookmarks", false); // misc confs to speed up FF profile.setPreference("extensions.ui.dictionary.hidden", true); profile.setPreference("layout.spellcheckDefault", 0); // For FF > 40 ? profile.setPreference("startup.homepage_welcome_url.additional", "about:blank"); // to ease up changing conf during tests profile.setPreference("general.warnOnAboutConfig", false); // webdriver logging if (Boolean.TRUE.equals(Boolean.valueOf(System.getenv("nuxeo.log.webriver")))) { String location = System.getProperty("basedir") + File.separator + "target"; File outputFolder = new File(location); if (!outputFolder.exists() || !outputFolder.isDirectory()) { outputFolder = null;/* w ww. ja v a2 s .c o m*/ } File webdriverlogFile = File.createTempFile("webdriver", ".log", outputFolder); profile.setPreference("webdriver.log.file", webdriverlogFile.getAbsolutePath()); log.warn("Webdriver logs saved in " + webdriverlogFile); } return profile; }
From source file:org.openlmis.UiUtils.DriverFactory.java
License:Open Source License
private WebDriver createFirefoxDriver(boolean enableJavascript) { boolean headless = Boolean.parseBoolean(getProperty("headless", "false")); FirefoxProfile profile = new FirefoxProfile(); profile.setAcceptUntrustedCertificates(true); profile.setPreference("signed.applets.codebase_principal_support", true); profile.setPreference("javascript.enabled", enableJavascript); profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv"); profile.setPreference("browser.download.dir", new File(System.getProperty("user.dir")).getParent()); profile.setPreference("browser.download.folderList", 2); profile.setPreference("dom.storage.enabled", true); profile.setPreference("device.storage.enabled", true); if ((getProperty("os.name").toLowerCase().contains("mac")) && headless) { String LOCAL_FIREFOX_X11_PATH = "/opt/local/bin/firefox-x11"; File binaryFile = new File(LOCAL_FIREFOX_X11_PATH); FirefoxBinary binary = new FirefoxBinary(binaryFile); String LOCAL_X11_DISPLAY = ":5"; binary.setEnvironmentProperty("DISPLAY", LOCAL_X11_DISPLAY); return new FirefoxDriver(binary, profile); }/*from w ww . ja v a 2s . c om*/ return new FirefoxDriver(profile); }
From source file:org.opens.tanaguru.sebuilder.tools.ProfileFactory.java
License:Open Source License
/** * //from w ww. j a v a 2 s.c om * @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); // 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.orcid.integration.blackbox.web.shibboleth.ShibbolethTest.java
License:Open Source License
private void createFireFoxDriverWithModifyHeaders() throws IOException { FirefoxProfile fireFoxProfile = new FirefoxProfile(); File modifyHeaders = new File( System.getProperty("user.dir") + "/src/test/resources/modify-headers-0.7.1.1.xpi"); fireFoxProfile.setEnableNativeEvents(false); fireFoxProfile.addExtension(modifyHeaders); fireFoxProfile.setPreference("modifyheaders.headers.count", 2); fireFoxProfile.setPreference("modifyheaders.headers.action0", "Add"); fireFoxProfile.setPreference("modifyheaders.headers.name0", "persistent-id"); fireFoxProfile.setPreference("modifyheaders.headers.value0", "integration-test-" + System.currentTimeMillis() + "@orcid.org"); fireFoxProfile.setPreference("modifyheaders.headers.enabled0", true); fireFoxProfile.setPreference("modifyheaders.headers.action1", "Add"); fireFoxProfile.setPreference("modifyheaders.headers.name1", "Shib-Identity-Provider"); fireFoxProfile.setPreference("modifyheaders.headers.value1", "https://integrationtest.orcid.org/idp/shibboleth"); fireFoxProfile.setPreference("modifyheaders.headers.enabled1", true); fireFoxProfile.setPreference("modifyheaders.config.active", true); fireFoxProfile.setPreference("modifyheaders.config.alwaysOn", true); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setBrowserName("firefox"); capabilities.setPlatform(org.openqa.selenium.Platform.ANY); capabilities.setCapability(FirefoxDriver.PROFILE, fireFoxProfile); webDriver = new FirefoxDriver(capabilities); }