List of usage examples for org.openqa.selenium.firefox FirefoxProfile FirefoxProfile
public FirefoxProfile()
From source file:FirefoxConsoleExport.java
License:Open Source License
public FirefoxConsoleExport(int port) throws IOException { super(port);/*from www. j a v a 2 s .com*/ start(NanoHTTPD.SOCKET_READ_TIMEOUT, false); ClassLoader classLoader = FirefoxConsoleExport.class.getClassLoader(); DesiredCapabilities cap = new DesiredCapabilities(); cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); FirefoxProfile fp = new FirefoxProfile(); File extensionToInstall = new File(classLoader.getResource("firebug-2.0.16-fx.xpi").getFile()); File extension2 = new File(classLoader.getResource("consoleExport-0.5b5.xpi").getFile()); fp.addExtension(extensionToInstall); fp.addExtension(extension2); fp.setPreference("extensions.firebug.currentVersion", "2.0"); fp.setPreference("extensions.firebug.console.enableSites", "true"); fp.setPreference("extensions.firebug.net.enableSites", "true"); fp.setPreference("extensions.firebug.script.enableSites", "true"); fp.setPreference("extensions.firebug.allPagesActivation", "on"); fp.setPreference("extensions.firebug.consoleexport.active", "true"); fp.setPreference("extensions.firebug.consoleexport.serverURL", "http://127.0.0.1:9999"); cap.setCapability(FirefoxDriver.PROFILE, fp); driver = new FirefoxDriver(cap); }
From source file:FormFiller.java
private static WebDriver getNewFirefoxDriver() { FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("browser.download.folderList", 1); profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf"); profile.setPreference("pdfjs.disabled", true); profile.setPreference("plugin.scan.plid.all", false); profile.setPreference("plugin.scan.Acrobat", "90.0"); profile.setPreference("plugin.disable_full_page_plugin_for_types", "application/pdf"); return new FirefoxDriver(profile); }
From source file:ExperimentRunner.java
License:Apache License
private void setupFirefox() throws Exception { DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox(); FirefoxBinary binary = new FirefoxBinary(new File(firefoxBinary)); FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("browser.cache.disk.enable", false); profile.setPreference("browser.cache.disk_cache_ssl", false); profile.setPreference("browser.cache.memory.enable", false); profile.setPreference("browser.cache.offline.capacity", 0); profile.setPreference("browser.cache.offline.enable", false); profile.setPreference("media.cache_size", 0); profile.setPreference("network.http.use-cache", false); //profile.setPreference("brwoser.dom.window.dump.enabled", true); driver = new FirefoxDriver(binary, profile, desiredCapabilities); driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS); }
From source file:GeneralCookieDriver.java
License:Open Source License
public WebDriver getWebDriver(Browser browser, boolean privateBrowsing) { if (browser.equals(Browser.CHROME)) { DesiredCapabilities capabilities = DesiredCapabilities.chrome(); if (privateBrowsing) { capabilities.setCapability("chrome.switches", Arrays.asList("--incognito")); }/*from w w w .j ava2 s . c om*/ System.setProperty("webdriver.chrome.driver", chromeDriverLocation); return new ChromeDriver(capabilities); } else if (browser.equals(Browser.FIREFOX)) { FirefoxProfile ffp = new FirefoxProfile(); if (privateBrowsing) { ffp.setPreference("browser.privatebrowsing.dont_prompt_on_enter", true); ffp.setPreference("browser.privatebrowsing.autostart", true); } DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability(FirefoxDriver.PROFILE, ffp); return new FirefoxDriver(capabilities); } else if (browser.equals(Browser.IE)) { System.setProperty("webdriver.ie.driver", ieDriverLocation); DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); if (privateBrowsing) { System.err.println("Launching into browsing mode is not supported in IE."); return null; } return new InternetExplorerDriver(); } else if (browser.equals(Browser.SAFARI)) { if (privateBrowsing) { System.out .println("WARNING: Selenium does not support launching into Safari private browsing mode."); System.out .println(" You will be given 10 seconds to transition into the private browsing "); System.out.println(" mode before the tests begin!"); } return new SafariDriver(); } return null; }
From source file:at.tugraz.ist.cucumber.SeleniumStepdefs.java
License:Open Source License
private void runOnFirefox() { FirefoxProfile profile = new FirefoxProfile(); DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability("firefox_profile", profile); initDriver(capabilities);//from w ww.j a v a 2s .c o m }
From source file:bingbot.BingBot.java
public BingBot(boolean mobile) { rc = new RemoteControlConfiguration(); rc.setSingleWindow(false);/* w w w. ja v a2 s . co m*/ profile = new FirefoxProfile(); if (mobile) { profile.setPreference("general.useragent.override", "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16"); } driver = new FirefoxDriver(profile); try { seleniumServer = new SeleniumServer(); seleniumServer.start(); } catch (Exception ex) { Logger.getLogger(BingBot.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:botski.selenium.SocialBot.java
License:Apache License
/** * Initialises Firefox as the default browser *///w w w . j a va 2s . c o m public void initializeFirefox() { FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("webdriver.load.strategy", "fast"); profile.setPreference("browser.tabs.loadInBackground", false); profile.setPreference("browser.tabs.warnOnClose", false); profile.setPreference("browser.tabs.warnOnOpen", false); if (proxyHost != null) { profile.setPreference("network.proxy.type", 1); profile.setPreference("network.proxy.http", proxyHost); profile.setPreference("network.proxy.http_port", proxyPort); profile.setPreference("network.proxy.ssl", proxyHost); profile.setPreference("network.proxy.ssl_port", proxyPort); } browser = new FirefoxDriver(profile); browser.manage().timeouts().pageLoadTimeout(timeout, TimeUnit.MILLISECONDS); browser.manage().timeouts().setScriptTimeout(timeout, TimeUnit.MILLISECONDS); browser.manage().timeouts().implicitlyWait(timeout, TimeUnit.MILLISECONDS); javascript = (JavascriptExecutor) browser; browser.manage().window().setSize(new Dimension(1024, 768)); }
From source file:br.ufmg.dcc.saotome.beholder.selenium.SeleniumController.java
License:Apache License
/** * This method starts the selenium remote control using the parameters * informed by testng.xml file//from w ww .jav a 2 s . co m * @param parameters * @throws Exception */ @BeforeSuite(alwaysRun = true) @Parameters(value = { "parameters" }) public static void startSelenium(String parameters) { parametersMap = parameterScanner(parameters); parametersInfo(); String browserName = parametersMap.get("browser"), profile = parametersMap.get("profile"), chromeDriverBin = parametersMap.get("chromeDriverBin"), ieDriverBin = parametersMap.get("ieDriverBin"), chromeBin = parametersMap.get("chromeBin"), languages = parametersMap.get("languages"); if (browserName == null) { throw new IllegalArgumentException( String.format(ErrorMessages.ERROR_TEMPLATE_VARIABLE_NULL, "browser")); } if (driver == null) { if (BrowsersList.FIREFOX.equalsString(browserName)) { FirefoxProfile fp = new FirefoxProfile(); fp.setPreference("dom.max_script_run_time", 0); fp.setPreference("dom.max_chrome_script_run_time", 0); if (profile != null && !profile.isEmpty()) { fp.setPreference("webdriver.firefox.profile", profile); } if (languages != null && !languages.isEmpty()) { fp.setPreference("intl.accept_languages", languages); } driver = new WebDriverAdapter(new FirefoxDriver(fp)); } else if (BrowsersList.CHROME.equalsString(browserName)) { if (chromeBin == null) { throw new IllegalArgumentException( String.format(ErrorMessages.ERROR_TEMPLATE_VARIABLE_NULL, "chromeBin")); } // Optional, if not specified, WebDriver will search your path for chromedriver // in the system environment. (OBS: To evade problems, webdriver.chrome.driver MUST have a value. if (System.getProperty("webdriver.chrome.driver") == null || System.getProperty("webdriver.chrome.driver").isEmpty()) { if (chromeDriverBin == null) { throw new IllegalArgumentException( String.format(ErrorMessages.ERROR_TEMPLATE_VARIABLE_NULL, "chromeDriverBin")); } System.setProperty("webdriver.chrome.driver", chromeDriverBin); } ChromeOptions co = new ChromeOptions(); // Get the chrome binary directory path from System Envionment. co.setBinary(new File(chromeBin)); driver = new WebDriverAdapter(new ChromeDriver(co)); } else if (BrowsersList.IE.equalsString(browserName)) { if (ieDriverBin == null) { throw new IllegalArgumentException( String.format(ErrorMessages.ERROR_TEMPLATE_VARIABLE_NULL, "ieDriverBin")); } System.setProperty("webdriver.ie.driver", ieDriverBin); driver = new WebDriverAdapter(new InternetExplorerDriver()); } else if (BrowsersList.HTML_UNIT.equalsString(browserName)) { driver = new HtmlUnitDriver(true); } else { throw new IllegalArgumentException(ErrorMessages.ERROR_BROWSER_INVALID); } } /* Sets to all driver methods the global timeout of 1 second. * To tests, Timeouts must be specified on the components. */ SeleniumController.driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS); SeleniumController.builder = new SeleniumBuilder(driver); SeleniumController.browser = new SeleniumBrowser(); ListenerGateway.setWebDriver(driver); ListenerGateway.setParameters(parametersMap); }
From source file:calc.CalculatorUIT.java
public void testCodesCrud(DesiredCapabilities browser) throws Exception { ExtentReports logger = new ExtentReports("target//advancedReport.html", false); ExtentTest test1 = logger.startTest("Verify Target String"); ExtentTest test2 = logger.startTest("Verify Calculation Result"); WebDriver driver = null;// w ww .j a va 2 s. com System.out.println("Attempt connect to Selenium Node @ " + NodeURL); File pathToBinary = new File("/opt/firefox46/firefox/firefox-bin"); FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary); FirefoxProfile firefoxProfile = new FirefoxProfile(); driver = new FirefoxDriver(ffBinary, firefoxProfile); try { System.out.println("attempt connect to target: " + TargetURL); driver.get(TargetURL); //input a addition 12+8 example in the calculator web-application; driver.findElement(By.xpath("(//input[@id='buttonRow'])[2]")).click(); driver.findElement(By.xpath("(//input[@id='buttonRow'])[3]")).click(); driver.findElement(By.xpath("(//input[@id='buttonRow'])[12]")).click(); driver.findElement(By.xpath("(//input[@id='buttonRow'])[10]")).click(); driver.findElement(By.xpath("(//input[@id='buttonRow'])[15]")).click(); //search target string value String targetStr = "Welcome to the Demo"; //verify result boolean isFound = (driver.findElement(By.tagName("body")).getText()).contains(targetStr); boolean result = driver.findElement(By.name("display")).getAttribute("value").contains("84"); //verify title if (isFound == true) { test1.log(LogStatus.PASS, "Title has been verified"); } if (isFound == false) { test1.log(LogStatus.FAIL, "Title has NOT been verified"); } //verify result if (result == true) { test2.log(LogStatus.PASS, "The Calculation result was correct: [12 multiply by 7 gave output of 84]"); } else { test2.log(LogStatus.FAIL, "The Calculation result was not correct [the title is[Welcome to the Demo!]"); } logger.endTest(test1); logger.endTest(test2); logger.flush(); System.out.println("look for= [" + targetStr + "]"); System.out.println("did we find it? [" + isFound + "]"); System.out.println("calculate 12 multiply by 7"); System.out.println("Was the result 84 ? [" + result + "]"); Assert.assertTrue(isFound); Assert.assertTrue(result); // Assert.assertEquals("hell",driver.getTitle()); //doTest(driver); // rest of test commands come here } catch (Exception e) { e.printStackTrace(); Assert.assertTrue(e.getMessage(), false); } finally { if (driver != null) { driver.quit(); } } }
From source file:co.edu.icesi.i2t.slrtools.bib.transformations.TransformBibACM.java
License:Open Source License
/** * Funcion principal para la transformacion de los archivos html en un solo * arhivo consolidado BIB, la funcion se encarga de extraer del html cada * link de articulo, despues de tener el listado de url se dispone con la * ayuda de selenium webdriver el ingreso a cada url y descargar el BIBtex * para finalizar con la union de todos en un solo archivo BIB * * @param sourceFilesPath String con la ruta de la carpeta donde se * encuentran los archivos html a transformas * @param targetFilePath String con la ruta fisica del directorio donde se * guardara el archivo consolodidao//w ww . j a va 2s . c o m * @param targetFileName */ public static boolean transformFiles(String sourceFilesPath, String targetFilePath, String targetFileName) { boolean bibFileCreated = false; System.out.println(""); System.out.println("-----------------------------"); System.out.println("Generating BibTeX for ACM Digital Library results..."); System.out.println(""); String bibContent = ""; List<String> urls = extractURL(sourceFilesPath); FirefoxProfile profile = new FirefoxProfile(); WebDriver webDriver = new FirefoxDriver(profile); for (int i = 0; i < urls.size(); i++) { try { System.out.println("[INFO] Retrieving BibTeX from URL: " + urls.get(i)); String idFile = urls.get(i).split("id=")[1].split("&")[0]; idFile = idFile.substring(idFile.indexOf(".") + 1, idFile.length()); String url = (urls.get(i)); webDriver.get(url); WebElement bibField = (new WebDriverWait(webDriver, 10)) .until(ExpectedConditions.presenceOfElementLocated(By.linkText("BibTeX"))); try { Thread.sleep(2000); } catch (InterruptedException e) { } bibField.click(); WebElement textBib = (new WebDriverWait(webDriver, 10)) .until(ExpectedConditions.presenceOfElementLocated(By.id(idFile))); String reference = textBib.getText(); String referenceAbstract = webDriver.findElement(By.id("abstract")).getText(); referenceAbstract = "abstract = {" + referenceAbstract + "}}" + System.lineSeparator(); bibContent += reference.substring(0, reference.length() - 2) + referenceAbstract; //Thread.sleep(10000); //tempurl.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); } catch (TimeoutException e) { System.out.println( "[ERROR] Failed to retrieve BibTex. The application may have been blocked by ACM Digital Library. Try again later."); } catch (Exception e) { System.out.println("[ERROR] Failed to retrieve BibTeX. " + e.getMessage()); } } webDriver.quit(); try { saveBibFile(bibContent, targetFilePath, targetFileName); if (!bibContent.equals("")) { bibFileCreated = true; } } catch (Exception e) { System.out.println("[ERROR] Failed to create BibTeX file." + e.getMessage()); } System.out.println("-----------------------------"); return bibFileCreated; }