List of usage examples for org.openqa.selenium.firefox FirefoxProfile FirefoxProfile
public FirefoxProfile()
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); }
From source file:org.pentaho.ctools.suite.CToolsTestSuite.java
License:Open Source License
@BeforeClass public static void setUpClass() throws IOException { System.out.println("Master setup"); //System.setProperty("webdriver.log.file", "/dev/stdout"); //System.setProperty("webdriver.firefox.logfile", "/dev/stdout"); //Setting log preferences LoggingPreferences logs = new LoggingPreferences(); logs.enable(LogType.BROWSER, Level.ALL); logs.enable(LogType.SERVER, Level.ALL); logs.enable(LogType.DRIVER, Level.ALL); logs.enable(LogType.PROFILER, Level.ALL); logs.enable(LogType.CLIENT, Level.ALL); logs.enable(LogType.PERFORMANCE, Level.ALL); DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability(CapabilityType.LOGGING_PREFS, logs); //Inicialize DRIVER FirefoxProfile ffProfile = new FirefoxProfile(); ffProfile.setPreference("intl.accept_languages", "en-us"); capabilities.setCapability(FirefoxDriver.PROFILE, ffProfile); JavaScriptError.addExtension(ffProfile); driver = new FirefoxDriver(capabilities); driver.manage().window().maximize(); driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); //Inicialize WAIT wait = new FluentWait<WebDriver>(driver).withTimeout(30, TimeUnit.SECONDS).pollingEvery(1, TimeUnit.SECONDS) .ignoring(org.openqa.selenium.NoSuchElementException.class); //Inicialize BASEURL baseUrl = "http://localhost:8080/pentaho/"; }
From source file:org.qe4j.web.OpenWebDriver.java
License:Open Source License
/** * Construct a new fire fox profile to set auto download to desktop. * * @return FirefoxProfile/* www .j ava2 s . c o m*/ */ protected FirefoxProfile getFireFoxProfile() { FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("browser.download.dir", getDownloadDir()); profile.setPreference("browser.download.folderList", 0); // desktop profile.setPreference("browser.download.manager.showWhenStarting", false); profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream,application/zip"); return profile; }
From source file:org.safs.selenium.webdriver.lib.SelectBrowser.java
License:Open Source License
/** * // w ww . ja v a2s . co m * @param browserName String, the browser name, such as "explorer" * @param extraParameters Map<String,Object>, can be used to pass more browser parameters, such as proxy settings. * @return DesiredCapabilities */ public static DesiredCapabilities getDesiredCapabilities(String browserName, Map<String, Object> extraParameters) { String debugmsg = StringUtils.debugmsg(false); DesiredCapabilities caps = null; if (browserName.equals(BROWSER_NAME_IE)) { System.setProperty(SYSTEM_PROPERTY_WEBDRIVER_IE, "IEDriverServer.exe"); caps = DesiredCapabilities.internetExplorer(); caps.setCapability("nativeEvents", true); caps.setCapability("requireWindowFocus", true); //caps.setCapability("browserName", BROWSER_NAME_IE); } else if (browserName.equals(BROWSER_NAME_CHROME)) { System.setProperty(SYSTEM_PROPERTY_WEBDRIVER_CHROME, "chromedriver.exe"); caps = DesiredCapabilities.chrome(); // Disable extensions to avoid popping up 'Disable developer mode extensions' message by default. if (!extraParameters.containsKey(KEY_CHROME_DISABLE_EXTENSIONS)) { // Only execute if no user's setting extraParameters.put(KEY_CHROME_DISABLE_EXTENSIONS, "true"); } //caps.setCapability("browserName", BROWSER_NAME_CHROME); } else if (browserName.equals(BROWSER_NAME_EDGE)) { System.setProperty(SYSTEM_PROPERTY_WEBDRIVER_EDGE, "MicrosoftWebDriver.exe"); caps = DesiredCapabilities.edge(); //caps.setCapability("browserName", BROWSER_NAME_EDGE); } else if (browserName.equals(BROWSER_NAME_ANDROID_CHROME)) { System.setProperty(SYSTEM_PROPERTY_WEBDRIVER_CHROME, "chromedriver.exe"); caps = DesiredCapabilities.chrome(); ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.setExperimentalOption("androidPackage", "com.android.chrome"); caps.setCapability(ChromeOptions.CAPABILITY, chromeOptions); caps.setCapability(CapabilityType.BROWSER_NAME, BROWSER_NAME_CHROME); } else if (browserName.equals(BROWSER_NAME_IPAD_SIMULATOR_SAFARI)) { caps = new DesiredCapabilities(); caps.setCapability("device", "ipad"); caps.setCapability("simulator", "true"); caps.setCapability(CapabilityType.BROWSER_NAME, "safari"); } else { // default browser always caps = DesiredCapabilities.firefox(); caps.setCapability(CapabilityType.BROWSER_NAME, BROWSER_NAME_FIREFOX); } String unexpectedAlertBehaviour = Processor.getUnexpectedAlertBehaviour(); if (unexpectedAlertBehaviour == null) unexpectedAlertBehaviour = System .getProperty(DriverConstant.PROERTY_SAFS_TEST_UNEXPECTEDALERTBEHAVIOUR); if (unexpectedAlertBehaviour != null) { IndependantLog.debug(debugmsg + " Set '" + unexpectedAlertBehaviour + "' to '" + CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR + "'."); caps.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, unexpectedAlertBehaviour); } if (extraParameters != null && !extraParameters.isEmpty()) { //1. Add http proxy settings to Capabilities, if they exist Object proxysetting = extraParameters.get(KEY_PROXY_SETTING); if (proxysetting != null && proxysetting instanceof String) { org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy(); proxy.setHttpProxy(proxysetting.toString()); Object bypass = extraParameters.get(KEY_PROXY_BYPASS_ADDRESS); if (bypass != null && bypass instanceof String) { proxy.setNoProxy(bypass.toString()); } caps.setCapability(CapabilityType.PROXY, proxy); } //2 Add firefox profile setting to Capabilities. if (BROWSER_NAME_FIREFOX.equals(browserName)) { //2.1 Add firefox profile setting to Capabilities, if it exists FirefoxProfile firefoxProfile = null; Object firefoxProfileParam = extraParameters.get(KEY_FIREFOX_PROFILE); if (firefoxProfileParam != null && firefoxProfileParam instanceof String) { //Can be profile's name or profile's file name String profileNameOrPath = firefoxProfileParam.toString(); IndependantLog.debug( debugmsg + "Try to Set firefox profile '" + profileNameOrPath + "' to Capabilities."); firefoxProfile = getFirefoxProfile(profileNameOrPath); if (firefoxProfile != null) { caps.setCapability(KEY_FIREFOX_PROFILE, profileNameOrPath);//used to store in session file } else { IndependantLog.error(debugmsg + " Fail to set firefox profile to Capabilities."); } } //2.2 Add firefox profile preferences to Capabilities, if it exists Object prefsFileParam = extraParameters.get(KEY_FIREFOX_PROFILE_PREFERENCE); if (prefsFileParam != null && prefsFileParam instanceof String) { String preferenceFile = prefsFileParam.toString(); IndependantLog.debug(debugmsg + "Try to Set firefox preference file '" + preferenceFile + "' to Firefox Profile."); caps.setCapability(KEY_FIREFOX_PROFILE_PREFERENCE, preferenceFile);//used to store in session file Map<?, ?> firefoxPreference = Json.readJSONFileUTF8(preferenceFile); if (firefoxProfile == null) firefoxProfile = new FirefoxProfile(); addFireFoxPreference(firefoxProfile, firefoxPreference); } if (firefoxProfile != null) { caps.setCapability(FirefoxDriver.PROFILE, firefoxProfile); } } //3. Add chrome-options-settings to Capabilities. if (BROWSER_NAME_CHROME.equals(browserName) || BROWSER_NAME_ANDROID_CHROME.equals(browserName)) { setChromeCapabilities(caps, extraParameters); } //put extra grid-nodes information Object gridnodes = extraParameters.get(KEY_GRID_NODES_SETTING); if (gridnodes != null && gridnodes instanceof String) { caps.setCapability(KEY_GRID_NODES_SETTING, gridnodes); } } return caps; }
From source file:org.sugarcrm.voodoodriver.Firefox.java
License:Apache License
/** * Create a new firefox browser instance. *///w ww .ja v a 2 s .c om public void newBrowser() { FirefoxBinary b = new FirefoxBinary(); FirefoxProfile p = null; if (this.profile == null) { p = new FirefoxProfile(); } else { p = new FirefoxProfile(new java.io.File(this.profile)); } if (this.downloadDirectory != null) { try { p.setPreference("browser.download.dir", this.downloadDirectory); } catch (java.lang.IllegalArgumentException e) { System.err.println("Ill-formed downloaddir '" + this.downloadDirectory + "'"); System.exit(1); } p.setPreference("browser.download.manager.closeWhenDone", true); p.setPreference("browser.download.manager.retention", 0); p.setPreference("browser.download.manager.showAlertOnComplete", false); p.setPreference("browser.download.manager.scanWhenDone", false); p.setPreference("browser.download.manager.skipWinSecurityPolicyChecks", true); p.setPreference("browser.startup.page", 0); p.setPreference("browser.download.manager.alertOnEXEOpen", false); p.setPreference("browser.download.manager.focusWhenStarting", false); p.setPreference("browser.download.useDownloadDir", true); } if (this.webDriverLogDirectory != null) { File wdl = makeLogfileName(this.webDriverLogDirectory, "webdriver"); File fl = makeLogfileName(this.webDriverLogDirectory, "firefox"); System.out.println("(*) Creating WebDriver log " + wdl); p.setPreference("webdriver.log.file", wdl.toString()); System.out.println("(*) Creating Firefox log " + fl); p.setPreference("webdriver.firefox.logfile", fl.toString()); } DesiredCapabilities c = new DesiredCapabilities(); c.setCapability("unexpectedAlertBehaviour", "ignore"); FirefoxDriver ff = new FirefoxDriver(b, p, c); this.setDriver(ff); this.setBrowserOpened(); }
From source file:org.terasoluna.gfw.functionaltest.app.FirefoxDriverFactoryBean.java
License:Apache License
@Override public FirefoxDriver getObject() { FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("browser.startup.homepage_override.mstone", "ignore"); profile.setPreference("network.proxy.type", 0); return new FirefoxDriver(profile); }
From source file:org.terasoluna.gfw.tutorial.selenium.FirefoxDriverFactoryBean.java
License:Apache License
@Override public FirefoxDriver getObject() { FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("brouser.startup.homepage_override.mstone", "ignore"); profile.setPreference("network.proxy.type", 0); profile.setPreference("intl.accept_languages", "en-us,en"); return new FirefoxDriver(profile); }
From source file:org.terasoluna.gfw.tutorial.selenium.FunctionTestSupport.java
License:Apache License
private WebDriver newWebDriver() { WebDriver driver = null;/* w w w .j av a2s . c om*/ for (String activeProfile : getApplicationContext().getEnvironment().getActiveProfiles()) { if ("chrome".equals(activeProfile)) { driver = new ChromeDriver(); break; } else if ("firefox".equals(activeProfile)) { break; } else if ("ie".equals(activeProfile)) { driver = new InternetExplorerDriver(); break; } } if (driver == null) { FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("brouser.startup.homepage_override.mstone", "ignore"); profile.setPreference("network.proxy.type", 0); driver = new FirefoxDriver(profile); } webDrivers.add(driver); return driver; }
From source file:org.terasoluna.gfw.tutorial.selenium.WebDriverCreator.java
License:Apache License
/** * Create a WebDriver with any locale enabled. * <p>/* w w w. j a v a 2 s . c om*/ * Supports FireFox and Chrome only<br> * If you specify "en" as an argument, it starts in the English locale.<br> * If "" is specified as an argument, it starts without a locale. * </p> * @param localeStr * @return WebDriver Operation target browser */ public WebDriver createLocaleSpecifiedDriver(String localeStr) { for (String activeProfile : getApplicationContext().getEnvironment().getActiveProfiles()) { if ("chrome".equals(activeProfile)) { ChromeOptions options = new ChromeOptions(); options.addArguments("--lang=" + localeStr); return new ChromeDriver(options); } else if ("firefox".equals(activeProfile)) { break; } else if ("ie".equals(activeProfile)) { throw new UnsupportedOperationException( "It is not possible to start locale specified browser using InternetExplorer."); } else if ("phantomJs".equals(activeProfile)) { throw new UnsupportedOperationException( "It is not possible to launch locale specified browser using PhantomJS."); } } // The default browser is Firefox FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("intl.accept_languages", localeStr); profile.setPreference("brouser.startup.homepage_override.mstone", "ignore"); profile.setPreference("network.proxy.type", 0); return new FirefoxDriver(profile); }
From source file:org.terasoluna.gfw.tutorial.selenium.WebDriverCreator.java
License:Apache License
/** * Start WebDriver with download function enabled. * <p>//from w ww.ja v a2s. co m * Supports FireFox only<br> * </p> * @param downloadTempDirectory : Temporary storage directory for download * @return WebDriver instance with download function enabled */ public WebDriver createDownloadableWebDriver(String downloadTempDirectory) { for (String activeProfile : getApplicationContext().getEnvironment().getActiveProfiles()) { if ("chrome".equals(activeProfile) || "ie".equals(activeProfile) || "phantomJs".equals(activeProfile)) { throw new UnsupportedOperationException( "It is not possible to run tests using the download function on browsers other than FireFox."); } } FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("browser.download.dir", downloadTempDirectory); profile.setPreference("browser.download.folderList", 2); profile.setPreference("browser.download.lastDir", downloadTempDirectory); profile.setPreference("browser.helperApps.alwaysAsk.force", false); profile.setPreference("browser.download.manager.showWhenStarting", false); profile.setPreference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", false); profile.setPreference("pdfjs.disabled", true); profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf, text/csv, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, text/plain"); profile.setPreference("brouser.startup.homepage_override.mstone", "ignore"); profile.setPreference("network.proxy.type", 0); WebDriver webDriver = new FirefoxDriver(profile); webDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); return webDriver; }