List of usage examples for org.openqa.selenium.firefox FirefoxProfile FirefoxProfile
public FirefoxProfile()
From source file:com.jaeksoft.searchlib.crawler.web.browser.FirefoxBrowserDriver.java
License:Open Source License
@Override public FirefoxDriver initialize() { FirefoxProfile profile = new FirefoxProfile(); // profile.setPreference("network.http.phishy-userpass-length", 255); profile.setEnableNativeEvents(false); return new FirefoxDriver(profile); }
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 a va2 s . c o m 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 ww w. j a v a 2s .com */ 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 {/* ww w .j av a 2s . co m*/ 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;/*from w ww .ja va2 s .c o m*/ 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;/*from w w w . j a v a 2 s . c om*/ 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; 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; }
From source file:com.moodle.test.SeleniumManager.java
License:GNU General Public License
/** * Run tests using the Firefox driver.//from w w w.java2 s .co m * @throws MalformedURLException Catches an exception caused by a malformed URL. All URL's are malformed so this much be caught. */ //Firefox Driver public void startFirefoxDriver() throws MalformedURLException { FirefoxProfile profile = new FirefoxProfile(); profile.setEnableNativeEvents(true); firefoxdriver = new FirefoxDriver(profile); }
From source file:com.mycompany.newseleniumtest.TestScript.java
public void startDriver(String browser) { switch (browser) { case "firefox": FirefoxProfile fp = new FirefoxProfile(); fp.setPreference("browser.startup.homepage", "about:blank"); fp.setPreference("startup.homepage_welcome_url", "about:blank"); fp.setPreference("startup.homepage_welcome_url.additional", "about:blank"); this.driver = new FirefoxDriver(fp); this.driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); driver.manage().window().maximize(); break;//from w w w . jav a 2 s . c o m case "chrome": System.setProperty("webdriver.chrome.driver", "/Users/rahmatzailani/Documents/chromedriver"); this.driver = new ChromeDriver(); this.driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); break; default: break; } }
From source file:com.mycompany.newseleniumtest.TestScript2.java
public void startDriver(String browser) { switch (browser) { case "firefox": FirefoxProfile fp = new FirefoxProfile(); fp.setPreference("browser.startup.homepage", "about:blank"); fp.setPreference("startup.homepage_welcome_url", "about:blank"); fp.setPreference("startup.homepage_welcome_url.additional", "about:blank"); this.driver = new FirefoxDriver(fp); this.driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); driver.manage().window().maximize(); //pras break;//from ww w. j a va 2 s . c o m case "chrome": System.setProperty("webdriver.chrome.driver", "/Users/kevinwibowo/Documents/Project/chromedriver"); this.driver = new ChromeDriver(); this.driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); break; default: break; } }
From source file:com.pentaho.selenium.BaseTest.java
License:Apache License
@BeforeSuite public void setUpClass() { this.log.info("Master setup"); // Initialize BASEURL baseUrl = "http://localhost:8080/pentaho/"; downloadDir = System.getProperty("user.home") + "\\SeleniumDonwloadDir"; pentahoReleaseVersion = System.getProperty("pentaho.release.version"); pentahoBaServerServiceName = System.getProperty("pentaho.bi.server.service.name"); pentahoBaServerUrl = System.getProperty("pentaho.bi.server.url"); pentahoBaServerHostname = System.getProperty("pentaho.bi.server.hostname"); pentahoBaServerPort = System.getProperty("pentaho.bi.server.port"); this.log.info("pentaho.release.version::" + pentahoReleaseVersion); new File(downloadDir).mkdir(); 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.WARNING); /*logs.enable( LogType.SERVER, Level.WARNING ); logs.enable( LogType.DRIVER, Level.WARNING ); logs.enable( LogType.PROFILER, Level.WARNING ); logs.enable( LogType.CLIENT, Level.WARNING ); logs.enable( LogType.PERFORMANCE, Level.WARNING );*/ /*/*from w w w . j a v a 2 s.co m*/ * INTERNET EXPLORER DRIVER */ // Initialize DRIVER FirefoxProfile ffProfile = new FirefoxProfile(); //ffProfile.setEnableNativeEvents( true ); ffProfile.setPreference("general.useragent.locale", "en-US"); ffProfile.setPreference("intl.accept_languages", "en-US, en"); ffProfile.setPreference("browser.download.folderList", 2); // 0 - Desktop, 1- Download dir, 2 - specify dir ffProfile.setPreference("browser.helperApps.alwaysAsk.force", false); ffProfile.setPreference("browser.download.manager.showWhenStarting", false); ffProfile.setPreference("browser.download.dir", downloadDir); ffProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "table/excel;application/vnd.ms-excel;application/msexcel;application/x-msexcel;application/x-ms-excel;application/x-excel;application/x-dos_ms_excel;application/xls;application/x-xls;application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;text/csv;application/rtf"); // Setting properties for webdriver DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability(CapabilityType.LOGGING_PREFS, logs); capabilities.setCapability(FirefoxDriver.PROFILE, ffProfile); BaseTest.driver = new FirefoxDriver(capabilities); /* * INTERNET EXPLORER DRIVER */ /* * System.setProperty("webdriver.ie.driver", "C:\\IEDriverServer_Win32_2.44.0\\IEDriverServer.exe"); * System.setProperty("webdriver.ie.driver.host", "10.120.42.25"); * System.setProperty("webdriver.ie.driver.loglevel", "FATAL"); System.setProperty("webdriver.ie.driver.loglevel", * downloadDir + "\\seleniumlogs.txt"); * * // We could use any driver for our tests... DesiredCapabilities capabilities = new DesiredCapabilities(); * capabilities.setBrowserName("internet explorer"); capabilities.setVersion("8"); * capabilities.setPlatform(Platform.WINDOWS); capabilities.setCapability("platform", "WINDOWS"); * capabilities.setJavascriptEnabled(true); //capabilities.setCapability(InternetExplorerDriver.HOST, * "10.120.40.243"); * * capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); * capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true); * * // Get a handle to the driver. This will throw an exception // if a matching driver cannot be located driver = * new RemoteWebDriver(new URL("http://10.120.42.25:4444/wd/hub"), capabilities); //driver = new * InternetExplorerDriver(); */ BaseTest.driver.manage().window().setPosition(new Point(0, 0)); BaseTest.driver.manage().window().setSize(new Dimension(1360, 764)); BaseTest.driver.manage().timeouts().pageLoadTimeout(180, TimeUnit.SECONDS); BaseTest.driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); BaseTest.driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS); // Initialize WAIT wait = new FluentWait<WebDriver>(BaseTest.driver).withTimeout(30, TimeUnit.SECONDS).pollingEvery(5, TimeUnit.SECONDS); }