List of usage examples for org.openqa.selenium.firefox FirefoxProfile setPreference
public void setPreference(String key, Object value)
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 .j a va2s . 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 w ww . j a v a 2 s. co 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 );*/ /*/* w w w. j a va 2s. 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); }
From source file:com.raja.anucarita.SeWrapper.java
License:Open Source License
public static WebDriver getDriver() throws Exception { if (Browser.equals("Firefox")) { FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("capability.policy.default.Window.QueryInterface", "allAccess"); profile.setPreference("capability.policy.default.Window.frameElement.get", "allAccess"); driver = new FirefoxDriver(profile); } else if (Browser.equals("IE")) { driver = new InternetExplorerDriver(); } else if (Browser.equals("GoogleChrome")) { System.setProperty("webdriver.chrome.driver", values.getProperty("GoogleChromeLocation")); driver = new ChromeDriver(); } else {/* www . j a v a 2 s. c o m*/ throw new Exception("Browser String is wrong"); } return driver; }
From source file:com.sat.dbds.utils.selenium.SeleniumUtilities.java
License:Open Source License
/** * Opens the Firefox instance for Selenium. *//* w w w . ja v a 2 s .co m*/ public static void openBrowser() { if (System.getProperty("run.type") == null || System.getProperty("run.type").equalsIgnoreCase("WUI")) { if (getDriver() != null) System.out.println(getDriver().toString() + "hi"); if (getDriver() == null || (!getDriver().toString().contains("-"))) { try { String browser = Validate.readsystemvariable("browser"); LogHandler.info("Browser:" + browser); String digest = Validate.readsystemvariable("browser.digest"); LogHandler.info("Digest Auth:" + digest); if (browser.equals("firefox") && digest.toUpperCase().equals("YES")) { LogHandler.info("Fire Fox Driver with addon configuration"); FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("browser.link.open_newwindow", 2); File extentions = new File(System.getProperty("user.dir") + Validate.readsystemvariable("firefox.addons.path")); if (extentions.exists()) { for (File extention : extentions.listFiles()) { if (extention.getName().endsWith(".xpi")) { try { profile.addExtension(new File(extention.getAbsolutePath())); } catch (IOException e) { Assert.assertTrue( "Exception occured while adding the extension to the profile..", false); } LogHandler.info("Added extention: " + extention.getName()); } } } driver = new FirefoxDriver(profile); } else if (browser.equals("firefox") && digest.toUpperCase().equals("NO")) { LogHandler.info("Fire Fox Driver without addon configuration"); driver = new FirefoxDriver(); } else if (browser.equals("chrome")) { LogHandler.info("Chrome Driver configuration"); JarFile jarFile = jarfilehandler.jarForClass(SeleniumUtilities.class); jarfilehandler.copyResourcesToDirectory(jarFile, "chrome", "src/it/resources/chrome"); System.setProperty("webdriver.chrome.driver", "src/it/resources/chrome/chromedriver.exe"); driver = new ChromeDriver(); } else if (browser.equals("IE")) { LogHandler.info("IE Driver configuration"); DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); String IEpath = (SeleniumUtilities.class).getResource("").getPath(); System.out.println(IEpath.substring(0, IEpath.length() - 31)); capabilities.setCapability( InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); JarFile jarFile = jarfilehandler.jarForClass(SeleniumUtilities.class); // JarFile jarFile = new // JarFile("C:\\Users\\amsathishkumar\\.m2\\repository\\com\\cisco\\dbds\\Utils\\0.0.1-Release\\Utils-0.0.1-Release.jar"); jarfilehandler.copyResourcesToDirectory(jarFile, "internetexplorer", "src/it/resources/InternetExplorer"); System.setProperty("webdriver.ie.driver", "src/it/resources/internetexplorer/IEDriverServer.exe"); driver = new InternetExplorerDriver(capabilities); // driver = new InternetExplorerDriver(); } else { Assert.assertTrue("include the browswer variable...", false); } } catch (Exception e) { LogHandler.info("Check the varaiables: browser,firefox.addons.path,user.dir"); } // driver.manage().timeouts().pageLoadTimeout(3, TimeUnit.SECONDS); // driver.manage().timeouts().setScriptTimeout(10, TimeUnit.SECONDS); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(Integer.parseInt(System.getProperty("implicit.wait")), TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(Integer.parseInt(System.getProperty("explicit.wait")), TimeUnit.SECONDS); System.out.println(getDriver().toString() + "hi"); } } }
From source file:com.sat.spvgt.utils.selenium.SeleniumUtilities.java
License:Open Source License
/** * Opens the Firefox instance for Selenium. *//*from w w w . jav a 2s . c om*/ public static void openBrowser() { if (System.getProperty("run.type") == null) { try { if (getDriver() == null || (!getDriver().toString().contains("-"))) { String browser = miscValidate.readsystemvariable("browser"); LogHandler.info("Browser:" + browser); String digest = miscValidate.readsystemvariable("browser.digest"); LogHandler.info("Digest Auth:" + digest); if (browser.equals("firefox") && digest.toUpperCase().equals("YES")) { LogHandler.info("Fire Fox Driver with addon configuration"); FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("browser.link.open_newwindow", 2); File extentions = new File(System.getProperty("user.dir") + miscValidate.readsystemvariable("firefox.addons.path")); if (extentions.exists()) { for (File extention : extentions.listFiles()) { if (extention.getName().endsWith(".xpi")) { try { profile.addExtension(new File(extention.getAbsolutePath())); } catch (IOException e) { Assert.assertTrue( "Exception occured while adding the extension to the profile..", false); } LogHandler.info("Added extention: " + extention.getName()); } } } driver = new FirefoxDriver(profile); } else if (browser.equals("firefox") && digest.toUpperCase().equals("NO")) { LogHandler.info("Fire Fox Driver without addon configuration"); driver = new FirefoxDriver(); } else if (browser.equals("chrome")) { LogHandler.info("Chrome Driver configuration"); JarFile jarFile = miscJarfileHandler.jarForClass(SeleniumUtilities.class); miscJarfileHandler.copyResourcesToDirectory(jarFile, "chrome", "src/it/resources/chrome"); System.setProperty("webdriver.chrome.driver", "src/it/resources/chrome/chromedriver.exe"); driver = new ChromeDriver(); } else if (browser.equals("IE")) { LogHandler.info("IE Driver configuration"); DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); String IEpath = (SeleniumUtilities.class).getResource("").getPath(); System.out.println(IEpath.substring(0, IEpath.length() - 31)); capabilities.setCapability( InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); JarFile jarFile = miscJarfileHandler.jarForClass(SeleniumUtilities.class); // JarFile jarFile = new // JarFile("C:\\Users\\amsathishkumar\\.m2\\repository\\com\\cisco\\dbds\\Utils\\0.0.1-Release\\Utils-0.0.1-Release.jar"); miscJarfileHandler.copyResourcesToDirectory(jarFile, "internetexplorer", "src/it/resources/InternetExplorer"); System.setProperty("webdriver.ie.driver", "src/it/resources/internetexplorer/IEDriverServer.exe"); driver = new InternetExplorerDriver(capabilities); // driver = new InternetExplorerDriver(); } else { Assert.assertTrue("include the browswer variable...", false); } } } catch (Exception e) { LogHandler.info("Check the varaiables: browser,firefox.addons.path,user.dir"); } // driver.manage().timeouts().pageLoadTimeout(3, TimeUnit.SECONDS); // driver.manage().timeouts().setScriptTimeout(10, // TimeUnit.SECONDS); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(Integer.parseInt(System.getProperty("implicit.wait")), TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(Integer.parseInt(System.getProperty("explicit.wait")), TimeUnit.SECONDS); } }
From source file:com.saucelabs.sauce_ondemand.driver.SauceOnDemandSPIImpl.java
License:Open Source License
private void populateProfilePreferences(FirefoxProfile profile, Map<String, List<String>> paramMap) { for (Map.Entry<String, List<String>> mapEntry : paramMap.entrySet()) { String key = mapEntry.getKey(); if (Arrays.binarySearch(NON_PROFILE_PARAMETERS, key) == -1) { //add it to the profile profile.setPreference(key, getFirstParameter(paramMap, key)); }/*ww w .j a v a 2s .c om*/ } }
From source file:com.screenslicer.core.scrape.Scrape.java
License:Open Source License
private static void start(int pageLoadTimeout, Proxy proxy) { for (int i = 0; i < RETRIES; i++) { try {// ww w . j a v a2 s . c o m FirefoxProfile profile = new FirefoxProfile(new File("./firefox-profile")); if (proxy != null) { if (!CommonUtil.isEmpty(proxy.username) || !CommonUtil.isEmpty(proxy.password)) { String user = proxy.username == null ? "" : proxy.username; String pass = proxy.password == null ? "" : proxy.password; profile.setPreference("extensions.closeproxyauth.authtoken", Base64.encodeBase64String((user + ":" + pass).getBytes("utf-8"))); } else { profile.setPreference("extensions.closeproxyauth.authtoken", ""); } if (Proxy.TYPE_SOCKS_5.equals(proxy.type) || Proxy.TYPE_SOCKS_4.equals(proxy.type)) { profile.setPreference("network.proxy.type", 1); profile.setPreference("network.proxy.socks", proxy.ip); profile.setPreference("network.proxy.socks_port", proxy.port); profile.setPreference("network.proxy.socks_remote_dns", true); profile.setPreference("network.proxy.socks_version", Proxy.TYPE_SOCKS_5.equals(proxy.type) ? 5 : 4); } else if (Proxy.TYPE_SSL.equals(proxy.type)) { profile.setPreference("network.proxy.type", 1); profile.setPreference("network.proxy.ssl", proxy.ip); profile.setPreference("network.proxy.ssl_port", proxy.port); } else if (Proxy.TYPE_HTTP.equals(proxy.type)) { profile.setPreference("network.proxy.type", 1); profile.setPreference("network.proxy.http", proxy.ip); profile.setPreference("network.proxy.http_port", proxy.port); } } driver = new FirefoxDriver(profile); driver.manage().timeouts().pageLoadTimeout(pageLoadTimeout, TimeUnit.SECONDS); driver.manage().timeouts().setScriptTimeout(pageLoadTimeout, TimeUnit.SECONDS); driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); break; } catch (Throwable t1) { if (driver != null) { try { forceQuit(); driver = null; } catch (Throwable t2) { Log.exception(t2); } } Log.exception(t1); } } }
From source file:com.seleniumtests.browserfactory.MarionetteCapabilitiesFactory.java
License:Apache License
protected void configProfile(final FirefoxProfile profile, final DriverConfig webDriverConfig) { profile.setAcceptUntrustedCertificates(webDriverConfig.isSetAcceptUntrustedCertificates()); profile.setAssumeUntrustedCertificateIssuer(webDriverConfig.isSetAssumeUntrustedCertificateIssuer()); if (webDriverConfig.getFirefoxBinPath() != null) { System.setProperty("webdriver.firefox.bin", webDriverConfig.getFirefoxBinPath()); }/*from w w w.j a v a2 s.c o m*/ if (webDriverConfig.getUserAgentOverride() != null) { profile.setPreference("general.useragent.override", webDriverConfig.getUserAgentOverride()); } if (webDriverConfig.getNtlmAuthTrustedUris() != null) { profile.setPreference("network.automatic-ntlm-auth.trusted-uris", webDriverConfig.getNtlmAuthTrustedUris()); } if (webDriverConfig.getBrowserDownloadDir() != null) { profile.setPreference("browser.download.dir", webDriverConfig.getBrowserDownloadDir()); profile.setPreference("browser.download.folderList", 2); profile.setPreference("browser.download.manager.showWhenStarting", false); profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream,text/plain,application/pdf,application/zip,text/csv,text/html"); } if (!webDriverConfig.isEnableJavascript()) { profile.setPreference("javascript.enabled", false); } // fix permission denied issues profile.setPreference("capability.policy.default.Window.QueryInterface", "allAccess"); profile.setPreference("capability.policy.default.Window.frameElement.get", "allAccess"); profile.setPreference("capability.policy.default.HTMLDocument.compatMode.get", "allAccess"); profile.setPreference("capability.policy.default.Document.compatMode.get", "allAccess"); profile.setEnableNativeEvents(false); profile.setPreference("dom.max_chrome_script_run_time", 0); profile.setPreference("dom.max_script_run_time", 0); }
From source file:com.tascape.qa.th.webui.comm.Firefox.java
License:Apache License
public Firefox(boolean enableFirebug) throws Exception { FirefoxProfile profile; ProfilesIni profileIni = new ProfilesIni(); String profileName = sysConfig.getProperty(SYSPROP_FF_PROFILE_NAME); if (profileName != null) { LOG.debug("Load Firefox profile named as {}", profileName); profile = profileIni.getProfile(profileName); } else {/*from w ww .j a v a 2s . c o m*/ LOG.debug("Load Firefox profile named as {}", DEFAULT_FF_PROFILE_NAME); profile = profileIni.getProfile(DEFAULT_FF_PROFILE_NAME); } if (profile == null) { throw new Exception("Cannot find Firefox profile"); } profile.setPreference("app.update.enabled", false); profile.setEnableNativeEvents(false); profile.setAcceptUntrustedCertificates(true); profile.setAssumeUntrustedCertificateIssuer(false); profile.setPreference("dom.max_chrome_script_run_time", 0); profile.setPreference("dom.max_script_run_time", 0); if (enableFirebug) { this.firebug = new Firebug(); this.firebug.updateProfile(profile); } long end = System.currentTimeMillis() + 180000; while (System.currentTimeMillis() < end) { try { super.setWebDriver(new FirefoxDriver(profile)); break; } catch (org.openqa.selenium.WebDriverException ex) { String msg = ex.getMessage(); LOG.warn(msg); if (!msg.contains("Unable to bind to locking port 7054 within 45000 ms")) { throw ex; } } } }