List of usage examples for org.openqa.selenium.firefox FirefoxProfile FirefoxProfile
public FirefoxProfile()
From source file:org.kuali.rice.testtools.selenium.JenkinsJsonJobsResults.java
License:Educational Community License
@Before public void setUp() throws MalformedURLException, InterruptedException { jenkinsBase = System.getProperty("jenkins.base.url", "http://ci.rice.kuali.org"); outputDirectory = System.getProperty("json.output.dir"); jobs = System.getProperty("jenkins.jobs", "rice-2.4-smoke-test").split("[,\\s]"); DesiredCapabilities capabilities = new DesiredCapabilities(); FirefoxProfile profile = new FirefoxProfile(); profile.setEnableNativeEvents(false); capabilities.setCapability(FirefoxDriver.PROFILE, profile); driver = new FirefoxDriver(capabilities); driver.manage().timeouts().implicitlyWait(WebDriverUtils.configuredImplicityWait(), TimeUnit.SECONDS); driver.get(jenkinsBase + "/login?form"); // CAS//from w w w .ja v a 2 s .c o m 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); if (driver.getPageSource().contains("The credentials you provided cannot be determined to be authentic.")) { System.out.println("CAS Login Error"); System.exit(1); } // 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()); passed = true; }
From source file:org.kuali.rice.testtools.selenium.JiraIssueCreation.java
License:Educational Community License
private void login() throws InterruptedException { DesiredCapabilities capabilities = new DesiredCapabilities(); FirefoxProfile profile = new FirefoxProfile(); profile.setEnableNativeEvents(false); capabilities.setCapability(FirefoxDriver.PROFILE, profile); driver = new FirefoxDriver(capabilities); driver.manage().timeouts().implicitlyWait(WebDriverUtils.configuredImplicityWait(), TimeUnit.SECONDS); driver.get(jiraBase + "/secure/Dashboard.jspa"); WebDriverUtils.waitFor(driver, WebDriverUtils.configuredImplicityWait(), By.className("login-link"), this.getClass().toString()).click(); // CAS/*www.j a v a 2 s .c om*/ 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(); }
From source file:org.kuali.rice.testtools.selenium.WebDriverUtils.java
License:Educational Community License
/** * <p>/* ww w .j a v a 2s .co m*/ * remote.public.driver set to chrome or firefox (null assumes firefox). * </p><p> * if remote.public.hub is set a RemoteWebDriver is created (Selenium Grid) * if proxy.host is set, the web driver is setup to use a proxy * </p> * * @return WebDriver or null if unable to create */ public static WebDriver getWebDriver() { String driverParam = System.getProperty(HUB_DRIVER_PROPERTY); String hubParam = System.getProperty(HUB_PROPERTY); String proxyParam = System.getProperty(PROXY_HOST_PROPERTY); // setup proxy if specified as VM Arg DesiredCapabilities capabilities = new DesiredCapabilities(); WebDriver webDriver = null; if (StringUtils.isNotEmpty(proxyParam)) { capabilities.setCapability(CapabilityType.PROXY, new Proxy().setHttpProxy(proxyParam)); } if (hubParam == null) { if (driverParam == null || "firefox".equalsIgnoreCase(driverParam)) { FirefoxProfile profile = new FirefoxProfile(); profile.setEnableNativeEvents(false); capabilities.setCapability(FirefoxDriver.PROFILE, profile); return new FirefoxDriver(capabilities); } else if ("chrome".equalsIgnoreCase(driverParam)) { return new ChromeDriver(capabilities); } else if ("safari".equals(driverParam)) { System.out.println("SafariDriver probably won't work, if it does please contact Erik M."); return new SafariDriver(capabilities); } } else { try { if (driverParam == null || "firefox".equalsIgnoreCase(driverParam)) { return new RemoteWebDriver(new URL(getHubUrlString()), DesiredCapabilities.firefox()); } else if ("chrome".equalsIgnoreCase(driverParam)) { return new RemoteWebDriver(new URL(getHubUrlString()), DesiredCapabilities.chrome()); } } catch (MalformedURLException mue) { System.out.println(getHubUrlString() + " " + mue.getMessage()); mue.printStackTrace(); } } return null; }
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()); }//from w ww . j av a2 s. c o m } } } 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.j a va2 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.mitre.mpf.wfm.ITWebUI.java
License:Open Source License
@BeforeClass public static void openBrowser() { //create a browser driver firefoxProfile = new FirefoxProfile(); firefoxProfile.setPreference("browser.private.browsing.autostart", true);// for opening more than one driver/browser at a time firefoxProfile.setPreference("accessibility.blockautorefresh", true);// block autorefresh on the nodemanager :8008 page firefoxProfile.setPreference("browser.cache.disk.enable", false);// clear cache firefoxProfile.setPreference("browser.cache.memory.enable", false); firefoxProfile.setPreference("browser.cache.offline.enable", false); firefoxProfile.setPreference("network.http.use-cache", false); firefoxProfile.setPreference("network.proxy.type", 0);//circumvent the proxy when hitting localhost driver = ITWebUI.getDriver();/*from ww w. j av a2 s .c o m*/ }
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);/*from w w w . ja va 2 s . co m*/ 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.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;//from ww w . ja v a 2 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); }// ww w. j a v a 2s . c o m return new FirefoxDriver(profile); }
From source file:org.opens.tanaguru.sebuilder.tools.ProfileFactory.java
License:Open Source License
/** * /*w w w. j av a 2s . c om*/ * @return * a set-up Firefox profile */ private FirefoxProfile getProfile(boolean loadImage) { FirefoxProfile firefoxProfile = new FirefoxProfile(); setUpPreferences(firefoxProfile, loadImage); // setUpExtensions(firefoxProfile); setUpProxy(firefoxProfile); return firefoxProfile; }