List of usage examples for org.openqa.selenium.firefox FirefoxProfile setPreference
public void setPreference(String key, Object value)
From source file:com.ceiwc.compugain.setup.TestBase.java
public WebDriver initializeDriver(String sbrowser, String sgrid) { WebDriver driver = null;//from www .jav a 2 s .c om logger.info("Test Base Version is" + Configuration.getGrid()); logger.info("Test Base Browser is" + sbrowser); sgrid = Configuration.getGrid(); if (sgrid.equalsIgnoreCase("")) { sbrowser = Configuration.getAutomationBrowser(); return driver = initializeDriver(sbrowser); } else if (!sgrid.equalsIgnoreCase("") && !sbrowser.equalsIgnoreCase("")) { logger.info("I am in Grid Intialization"); DesiredCapabilities capabilities = new DesiredCapabilities(); URL hubUrl = null; try { hubUrl = new URL("http://localhost:4444/wb/hub"); if (sbrowser.equalsIgnoreCase("firefox")) { FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("browser.download.folderList", 2); capabilities.setBrowserName(DesiredCapabilities.firefox().getBrowserName()); capabilities.setPlatform(Platform.WINDOWS); driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities); //remoteWebDriver.setFileDetector(new LocalFileDetector()); } if (sbrowser.equalsIgnoreCase("chrome")) { System.setProperty("webdriver.chrome.driver", getFilePath(CHROMEPATH)); capabilities.setBrowserName(DesiredCapabilities.chrome().getBrowserName()); //capabilities.setVersion(sversion1); capabilities.setPlatform(Platform.WINDOWS); driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities); } } catch (MalformedURLException e) { e.printStackTrace(); } } return driver; }
From source file:com.ceiwc.compugain.setup.TestBase.java
public WebDriver secondDriverInitialization(String sbrowser/*,String surl*/) { sbrowser = Configuration.getAutomationBrowser(); logger.info("Browser Name:" + sbrowser); // logger.info(" Application surl:"+surl); if (secondDriver == null) { if (sbrowser.equalsIgnoreCase("firefox")) { String downloadPath = FileOperation.getFilePath(DOWNLOADSPATH); FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("browser.download.folderList", 2); profile.setPreference("browser.download.manager.showWhenStarting", false); profile.setPreference("browser.download.dir", downloadPath); profile.setPreference("browser.helperApps.neverAsk.openFile", "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml"); profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml"); profile.setPreference("browser.helperApps.alwaysAsk.force", false); profile.setPreference("browser.download.manager.alertOnEXEOpen", false); profile.setPreference("browser.download.manager.focusWhenStarting", false); profile.setPreference("browser.download.manager.useWindow", false); profile.setPreference("browser.download.manager.showAlertOnComplete", false); profile.setPreference("browser.download.manager.closeWhenDone", false); profile.setPreference("xpinstall.signatures.required", false); logger.info("The Profile Setup Data"); secondDriver = new FirefoxDriver(profile); //secondDriver = new FirefoxDriver(firefoxProfileSetUp()); /* webdriver= new EventFiringWebDriver(driver); EventListerners eventListerners=new EventListerners(); webdriver.register(eventListerners); *///from w w w.java2s . com } else if (sbrowser.equalsIgnoreCase("Chrome")) { /*System.setProperty("webdriver.chrome.driver", getFilePath(CHROMEPATH)); HashMap<String, Object> chromePrefs = new HashMap<String, Object>(); chromePrefs.put("profile.default_content_settings.popups", 0); chromePrefs.put("download.default_directory",getFilePath(DOWNLOADSPATH)); ChromeOptions options = new ChromeOptions(); HashMap<String, Object> chromeOptionsMap = new HashMap<String, Object>(); options.setExperimentalOption("prefs", chromePrefs); options.addArguments("--test-type"); DesiredCapabilities cap = DesiredCapabilities.chrome(); cap.setCapability(ChromeOptions.CAPABILITY, chromeOptionsMap); cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); cap.setCapability(ChromeOptions.CAPABILITY, options); */ secondDriver = new ChromeDriver(chromeProfileSetUp()); //secondDriver = new ChromeDriver(chromeProfileSetUp()); /* webdriver= new EventFiringWebDriver(driver); EventListerners eventListerners=new EventListerners(); webdriver.register(eventListerners); */ } else if (sbrowser.equalsIgnoreCase("IE")) { /*if (System.getProperty("os.arch").contains("86")) { logger.info("System is---"+System.getProperty("os.arch")+"---bit"); System.setProperty("webdriver.ie.driver", getFilePath("/src/test/resources/Browsers_Binaries/IE/IEDriverServer64.exe")); } else if (System.getProperty("os.arch").contains("64")) { logger.info("System is---"+System.getProperty("os.arch")+"---bit"); System.setProperty("webdriver.ie.driver", getFilePath("/src/test/resources/Browsers_Binaries/IE/IEDriverServer64.exe")); }*/ secondDriver = new InternetExplorerDriver(ieProfileSetUp()); /*webdriver= new EventFiringWebDriver(driver); EventListerners eventListerners=new EventListerners(); webdriver.register(eventListerners); */} else if (sbrowser.equalsIgnoreCase("Safari")) { DesiredCapabilities capabilities = DesiredCapabilities.safari(); secondDriver = new SafariDriver(capabilities); /* webdriver= new EventFiringWebDriver(driver); EventListerners eventListerners=new EventListerners(); webdriver.register(eventListerners); */} } secondDriver.manage().timeouts().implicitlyWait(1, TimeUnit.MINUTES); return secondDriver; }
From source file:com.ceiwc.compugain.setup.TestBase.java
public WebDriver thirdDriverInitialization(String sbrowser/*,String surl*/) { sbrowser = Configuration.getAutomationBrowser(); logger.info("Browser Name:" + sbrowser); // logger.info(" Application surl:"+surl); if (thirdDriver == null) { if (sbrowser.equalsIgnoreCase("firefox")) { String downloadPath = FileOperation.getFilePath(DOWNLOADSPATH); FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("browser.download.folderList", 2); profile.setPreference("browser.download.manager.showWhenStarting", false); profile.setPreference("browser.download.dir", downloadPath); profile.setPreference("browser.helperApps.neverAsk.openFile", "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml"); profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml"); profile.setPreference("browser.helperApps.alwaysAsk.force", false); profile.setPreference("browser.download.manager.alertOnEXEOpen", false); profile.setPreference("browser.download.manager.focusWhenStarting", false); profile.setPreference("browser.download.manager.useWindow", false); profile.setPreference("browser.download.manager.showAlertOnComplete", false); profile.setPreference("browser.download.manager.closeWhenDone", false); profile.setPreference("xpinstall.signatures.required", false); logger.info("The Profile Setup Data"); thirdDriver = new FirefoxDriver(profile); //thirdDriver = new FirefoxDriver(firefoxProfileSetUp()); /* webdriver= new EventFiringWebDriver(driver); EventListerners eventListerners=new EventListerners(); webdriver.register(eventListerners); */} else if (sbrowser.equalsIgnoreCase("Chrome")) { thirdDriver = new ChromeDriver(chromeProfileSetUp()); } else if (sbrowser.equalsIgnoreCase("IE")) { thirdDriver = new InternetExplorerDriver(ieProfileSetUp()); } else if (sbrowser.equalsIgnoreCase("Safari")) { DesiredCapabilities capabilities = DesiredCapabilities.safari(); thirdDriver = new SafariDriver(capabilities); }// w w w. ja v a 2 s . com } thirdDriver.manage().timeouts().implicitlyWait(1, TimeUnit.MINUTES); return thirdDriver; //return webdriver; }
From source file:com.ceiwc.compugain.setup.TestBase.java
public WebDriver driverIntialization(String sbrowser) { WebDriver fourthdriver = null;/* w w w . j a va 2s .c o m*/ sbrowser = Configuration.getAutomationBrowser(); logger.info("Browser Name:" + sbrowser); if (fourthdriver == null) { if (sbrowser.equalsIgnoreCase("firefox")) { String downloadPath = FileOperation.getFilePath(DOWNLOADSPATH); FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("browser.download.folderList", 2); profile.setPreference("browser.download.manager.showWhenStarting", false); profile.setPreference("browser.download.dir", downloadPath); profile.setPreference("browser.helperApps.neverAsk.openFile", "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml"); profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml"); profile.setPreference("browser.helperApps.alwaysAsk.force", false); profile.setPreference("browser.download.manager.alertOnEXEOpen", false); profile.setPreference("browser.download.manager.focusWhenStarting", false); profile.setPreference("browser.download.manager.useWindow", false); profile.setPreference("browser.download.manager.showAlertOnComplete", false); profile.setPreference("browser.download.manager.closeWhenDone", false); profile.setPreference("xpinstall.signatures.required", false); logger.info("The Profile Setup Data"); fourthdriver = new FirefoxDriver(profile); } else if (sbrowser.equalsIgnoreCase("Chrome")) { fourthdriver = new ChromeDriver(chromeProfileSetUp()); } else if (sbrowser.equalsIgnoreCase("IE")) { fourthdriver = new InternetExplorerDriver(ieProfileSetUp()); } else if (sbrowser.equalsIgnoreCase("Safari")) { DesiredCapabilities capabilities = DesiredCapabilities.safari(); fourthdriver = new SafariDriver(capabilities); } } fourthdriver.manage().timeouts().implicitlyWait(1, TimeUnit.MINUTES); return fourthdriver; }
From source file:com.ceiwc.compugain.setup.TestBase.java
public FirefoxProfile firefoxProfileSetUp() { FirefoxProfile profile = new FirefoxProfile(); String downloadFilepath = getFilePath(DOWNLOADSPATH); profile.setPreference("browser.download.folderList", 2); profile.setPreference("browser.download.manager.showWhenStarting", false); profile.setPreference("browser.download.dir", downloadFilepath); profile.setPreference("browser.helperApps.neverAsk.openFile", "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml"); profile.setPreference("browser.helperApps.alwaysAsk.force", false); profile.setPreference("browser.download.manager.alertOnEXEOpen", false); profile.setPreference("browser.download.manager.focusWhenStarting", false); profile.setPreference("browser.download.manager.useWindow", false); profile.setPreference("browser.download.manager.showAlertOnComplete", false); profile.setPreference("browser.download.manager.closeWhenDone", false); profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml"); logger.info("Profile Setup done for firefox"); return profile; }
From source file:com.cisco.dbds.utils.selenium.SeleniumUtilities.java
License:Open Source License
/** * Opens the Firefox instance for Selenium. *//*from w ww . j a v a2 s . c o m*/ public static void openBrowser() { 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); }
From source file:com.citrix.g2w.webdriver.tests.BaseWebDriverTest.java
License:Open Source License
/** * Method to create new WebDriver by setting desired browser language. * //from w w w. java 2 s.co m * @param browserLanguage * (browser language) * @return (driver object depends on input) */ protected WebDriver getWebDriverBySettingDesiredBrowserLanguage(final String browserLanguage) { String driver = this.propertyUtil.getProperty("driver"); if ((driver != null) && (driver.equalsIgnoreCase("firefox"))) { FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("intl.accept_languages", browserLanguage); return new FirefoxDriver(profile); } else { BrowserVersion browserVersion = new BrowserVersion("null", "null", "null", 0); browserVersion.setBrowserLanguage(browserLanguage); return new HtmlUnitDriver(browserVersion); } }
From source file:com.consol.citrus.selenium.client.WebClient.java
License:Apache License
private FirefoxProfile createFireFoxProfile() { FirefoxProfile fp = new FirefoxProfile(); fp.setAcceptUntrustedCertificates(true); fp.setAssumeUntrustedCertificateIssuer(false); /* set custom download folder */ fp.setPreference("browser.download.dir", temporaryStorage.toFile().getAbsolutePath()); /* default download folder, set to 2 to use custom download folder */ fp.setPreference("browser.download.folderList", 2); /* comma separated list if MIME types to save without asking */ fp.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/plain"); /* do not show download manager */ fp.setPreference("browser.download.manager.showWhenStarting", false); fp.setEnableNativeEvents(true);//from w w w .ja v a2s . c om return fp; }
From source file:com.consol.citrus.selenium.endpoint.SeleniumBrowser.java
License:Apache License
/** * Creates local web driver.// w w w . ja va 2s . c o m * @param browserType * @return */ private WebDriver createLocalWebDriver(String browserType) { switch (browserType) { case BrowserType.FIREFOX: FirefoxProfile firefoxProfile = getEndpointConfiguration().getFirefoxProfile(); /* set custom download folder */ firefoxProfile.setPreference("browser.download.dir", temporaryStorage.toFile().getAbsolutePath()); DesiredCapabilities defaults = DesiredCapabilities.firefox(); defaults.setCapability(FirefoxDriver.PROFILE, firefoxProfile); return new FirefoxDriver(defaults); case BrowserType.IE: return new InternetExplorerDriver(); case BrowserType.EDGE: return new EdgeDriver(); case BrowserType.SAFARI: return new SafariDriver(); case BrowserType.CHROME: return new ChromeDriver(); case BrowserType.GOOGLECHROME: return new ChromeDriver(); case BrowserType.HTMLUNIT: BrowserVersion browserVersion = null; if (getEndpointConfiguration().getVersion().equals("FIREFOX")) { browserVersion = BrowserVersion.FIREFOX_45; } else if (getEndpointConfiguration().getVersion().equals("INTERNET_EXPLORER")) { browserVersion = BrowserVersion.INTERNET_EXPLORER; } else if (getEndpointConfiguration().getVersion().equals("EDGE")) { browserVersion = BrowserVersion.EDGE; } else if (getEndpointConfiguration().getVersion().equals("CHROME")) { browserVersion = BrowserVersion.CHROME; } HtmlUnitDriver htmlUnitDriver; if (browserVersion != null) { htmlUnitDriver = new HtmlUnitDriver(browserVersion); } else { htmlUnitDriver = new HtmlUnitDriver(); } htmlUnitDriver.setJavascriptEnabled(getEndpointConfiguration().isJavaScript()); return htmlUnitDriver; default: throw new CitrusRuntimeException("Unsupported local browser type: " + browserType); } }
From source file:com.crawljax.plugins.testilizer.generated.claroline_EXND.GeneratedTestCase11.java
public static FirefoxProfile getProfile() { FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("network.proxy.http", "localhost"); profile.setPreference("network.proxy.http_port", 3128); profile.setPreference("network.proxy.type", 1); /* use proxy for everything, including localhost */ profile.setPreference("network.proxy.no_proxies_on", ""); return profile; }