List of usage examples for org.openqa.selenium.firefox FirefoxDriver FirefoxDriver
public FirefoxDriver(FirefoxDriverService service)
From source file:FirefoxConsoleExport.java
License:Open Source License
public FirefoxConsoleExport(int port) throws IOException { super(port);/* w w w . jav a 2 s. co m*/ 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: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")); }// w w w. j av a2 s . co m 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:NumOfWHGamesTest.java
@Before public void setup() throws MalformedURLException, UnknownHostException { ProfilesIni allProfiles = new ProfilesIni(); FirefoxProfile myProfile = allProfiles.getProfile("SimBin"); myProfile.setAcceptUntrustedCertificates(true); myProfile.setAssumeUntrustedCertificateIssuer(false); driver2 = new FirefoxDriver(myProfile); WebDriverWait wait = new WebDriverWait(driver2, 15); driver2.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver2.navigate().to(urlWHGames);/*from w w w. j av a 2 s . c o m*/ driver2.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver2.navigate().to(urlWHGamesAZ); wait.until(ExpectedConditions.urlMatches(urlWHGamesAZ)); wait = new WebDriverWait(driver2, 30); driver2.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); }
From source file:LoginWHTest.java
@Before public void setup() throws MalformedURLException, UnknownHostException { ProfilesIni allProfiles = new ProfilesIni(); FirefoxProfile myProfile = allProfiles.getProfile("SimBin"); myProfile.setAcceptUntrustedCertificates(true); myProfile.setAssumeUntrustedCertificateIssuer(false); driver2 = new FirefoxDriver(myProfile); WebDriverWait wait = new WebDriverWait(driver2, 15); driver2.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver2.navigate().to(urlWHGames);// www.jav a 2 s . com driver2.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); }
From source file:bingbot.BingBot.java
public BingBot(boolean mobile) { rc = new RemoteControlConfiguration(); rc.setSingleWindow(false);//from www. ja v a 2 s . c o 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 *///from w w w. j a v a 2s. c om 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.com.esign.logistics.test.selenium.UITest.java
License:Open Source License
/** * Starts the driver and opens the homepage. *//*w ww. j a va 2 s. c o m*/ @BeforeClass public static void setup() { FirefoxOptions options = new FirefoxOptions(); options.setHeadless(Boolean.getBoolean("headless")); driver = new FirefoxDriver(options); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); home = new HomePage(driver); }
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// w ww. j ava 2s . c om * @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:browsermator.com.RunASingleTest.java
public void RunSingleTest(Procedure bugtorun, ProcedureView thisbugview, String TargetBrowser, String OSType) { SiteTest.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); switch (TargetBrowser) { // legacy file support case "Firefox-Marionette": // legacy file support if ("Windows".equals(OSType)) { System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-win32\\geckodriver.exe"); }// w ww . j av a 2 s . com if ("Windows32".equals(OSType)) { System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-win32\\geckodriver.exe"); } if ("Windows64".equals(OSType)) { System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-win64\\geckodriver.exe"); } if ("Mac".equals(OSType)) { System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-osx\\geckodriver"); } if ("Linux-32".equals(OSType)) { System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-linux32\\geckodriver"); } if ("Linux-64".equals(OSType)) { System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-linux64\\geckodriver"); } if (firefox_path != null) { System.setProperty("webdriver.firefox.bin", firefox_path); } try { DesiredCapabilities cap = DesiredCapabilities.firefox(); cap.setJavascriptEnabled(true); cap.setCapability("marionette", true); driver = new FirefoxDriver(cap); // driver = new MarionetteDriver(); } catch (Exception ex) { System.out.println("Exception launching Marionette driver... possibly XP or missing msvcr110.dll: " + ex.toString()); Prompter fallbackprompt = new Prompter( "We could not launch the Marionette driver, will fallback to HTMLUnitDriver", false); SiteTest.setTargetBrowser("Silent Mode (HTMLUnit)"); } break; case "Firefox": //legacy support if ("Windows".equals(OSType)) { System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-win32\\geckodriver.exe"); } if ("Windows32".equals(OSType)) { System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-win32\\geckodriver.exe"); } if ("Windows64".equals(OSType)) { System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-win64\\geckodriver.exe"); } if ("Mac".equals(OSType)) { System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-osx\\geckodriver"); } if ("Linux-32".equals(OSType)) { System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-linux32\\geckodriver"); } if ("Linux-64".equals(OSType)) { System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-linux64\\geckodriver"); } if (firefox_path != null) { System.setProperty("webdriver.firefox.bin", firefox_path); } try { DesiredCapabilities cap = DesiredCapabilities.firefox(); cap.setJavascriptEnabled(true); cap.setCapability("marionette", true); driver = new FirefoxDriver(cap); // driver = new MarionetteDriver(); } catch (Exception ex) { System.out.println("Exception launching Marionette driver... possibly XP or missing msvcr110.dll: " + ex.toString()); Prompter fallbackprompt = new Prompter( "We could not launch the Marionette driver, will fallback to HTMLUnitDriver", false); SiteTest.setTargetBrowser("Silent Mode (HTMLUnit)"); } break; case "Silent Mode (HTMLUnit)": driver = new HtmlUnitDriver(); break; case "Internet Explorer-32": System.setProperty("webdriver.ie.driver", "lib\\iedriverserver_win32\\IEDriverServer.exe"); try { driver = new InternetExplorerDriver(); } catch (Exception ex) { System.out.println("Exception launching Internet Explorer driver: " + ex.toString()); Prompter fallbackprompt = new Prompter( "We could not launch the Internet Explorer driver, will fallback to HTMLUnitDriver", false); SiteTest.setTargetBrowser("Silent Mode (HTMLUnit)"); } break; case "Internet Explorer-64": System.setProperty("webdriver.ie.driver", "lib\\iedriverserver_win64\\IEDriverServer.exe"); try { driver = new InternetExplorerDriver(); } catch (Exception ex) { System.out.println("Exception launching Internet Explorer-64 driver: " + ex.toString()); Prompter fallbackprompt = new Prompter( "We could not launch the Internet Explorer 64 driver, will fallback to HTMLUnitDriver", false); SiteTest.setTargetBrowser("Silent Mode (HTMLUnit)"); } break; case "Chrome": if ("Windows32".equals(OSType)) { System.setProperty("webdriver.chrome.driver", "lib\\chromedriver_win32\\chromedriver.exe"); } if ("Windows64".equals(OSType)) { System.setProperty("webdriver.chrome.driver", "lib\\chromedriver_win32\\chromedriver.exe"); } if ("Mac".equals(OSType)) { System.setProperty("webdriver.chrome.driver", "lib\\chromedriver_mac64\\chromedriver"); } if ("Linux-32".equals(OSType)) { System.setProperty("webdriver.chrome.driver", "lib\\chromedriver_linux32\\chromedriver-linux32"); } if ("Linux-64".equals(OSType)) { System.setProperty("webdriver.chrome.driver", "lib\\chromedriver_linux64\\chromedriver-linux64"); } try { driver = new ChromeDriver(); } catch (Exception ex) { System.out.println("Problem launching Chromedriver: " + ex.toString()); Prompter fallbackprompt = new Prompter( "We could not launch the Chrome driver, will fallback to HTMLUnitDriver", false); SiteTest.setTargetBrowser("Silent Mode (HTMLUnit)"); } break; case "Chrome (WinXP)": if (chrome_path != null) { System.setProperty("webdriver.chrome.bin", chrome_path); } System.setProperty("webdriver.chrome.driver", "lib\\chromedriver_win32\\chromedriver-winxp.exe"); try { driver = new ChromeDriver(); } catch (Exception ex) { System.out.println("Problem launching Chromedriver for XP: " + ex.toString()); Prompter fallbackprompt = new Prompter( "We could not launch the Chrome WinXP driver, will fallback to HTMLUnitDriver", false); SiteTest.setTargetBrowser("Silent Mode (HTMLUnit)"); } break; default: driver = new ChromeDriver(); break; } int WaitTime = SiteTest.GetWaitTime(); // driver.manage().timeouts().implicitlyWait(WaitTime, TimeUnit.SECONDS); int totalpause = WaitTime * 1000; if (!"Dataloop".equals(thisbugview.Type)) { for (Action ThisAction : bugtorun.ActionsList) { if (!ThisAction.Locked) { try { try { Thread.sleep(totalpause); } catch (Exception ex) { System.out.println("Exception when sleeping: " + ex.toString()); } String varfieldname = ""; if (ThisAction.Variable2.contains("[stored_varname-start]")) { varfieldname = ThisAction.Variable2; int indexof_end_tag = varfieldname.indexOf("[stored_varname-end]"); // assuming name of "[stored_varname-start]" and "[stored_varname-end]" String fieldname = varfieldname.substring(22, indexof_end_tag); ThisAction.Variable2 = SiteTest.GetStoredVariableValue(fieldname); ThisAction.RunAction(driver); ThisAction.Variable2 = "[stored_varname-start]" + fieldname + "[stored_varname-end]"; } else { ThisAction.RunAction(driver); } if (!"".equals(ThisAction.tostore_varvalue)) { SiteTest.VarHashMap.put(ThisAction.tostore_varname, ThisAction.tostore_varvalue); } } catch (Exception ex) { SiteTest.setCursor(Cursor.getDefaultCursor()); driver.close(); driver.quit(); break; } } else { ThisAction.Pass = true; } } } else { int number_of_rows = thisbugview.myTable.DataTable.getRowCount(); for (int x = 0; x < number_of_rows; x++) { for (Action ThisAction : bugtorun.ActionsList) { String original_value1 = ThisAction.Variable1; String original_value2 = ThisAction.Variable2; if (!ThisAction.Locked) { DataLoopVarParser var1Parser = new DataLoopVarParser(ThisAction.Variable1); DataLoopVarParser var2Parser = new DataLoopVarParser(ThisAction.Variable2); if (var1Parser.hasDataLoopVar == false && var2Parser.hasDataLoopVar == false) { if ("Pause with Continue Button".equals(ThisAction.Type)) { String pause_message = "Paused at record " + (x + 1) + " of " + number_of_rows; ThisAction.RunAction(driver, pause_message, this.SiteTest); } try { Thread.sleep(totalpause); } catch (Exception ex) { System.out.println("Exception when sleeping: " + ex.toString()); } try { String varfieldname = ""; if (ThisAction.Variable2.contains("[stored_varname-start]")) { varfieldname = ThisAction.Variable2; int indexof_end_tag = varfieldname.indexOf("[stored_varname-end]"); // assuming name of "[stored_varname-start]" and "[stored_varname-end]" String fieldname = varfieldname.substring(22, indexof_end_tag); ThisAction.Variable2 = SiteTest.GetStoredVariableValue(fieldname); ThisAction.RunAction(driver); ThisAction.Variable2 = "[stored_varname-start]" + fieldname + "[stored_varname-end]"; } else { ThisAction.RunAction(driver); } if (!"".equals(ThisAction.tostore_varvalue)) { SiteTest.VarHashMap.put(ThisAction.tostore_varname, ThisAction.tostore_varvalue); } } catch (Exception ex) { driver.close(); driver.quit(); ThisAction.Variable1 = original_value1; ThisAction.Variable2 = original_value2; SiteTest.setCursor(Cursor.getDefaultCursor()); break; } } else { String concat_variable; String concat_variable2; concat_variable = var1Parser.GetFullValue(x, thisbugview.myTable); if (var1Parser.hasDataLoopVar) { ThisAction.Variable1 = concat_variable; if ("".equals(ThisAction.Variable1)) { ThisAction.Variable1 = " "; } } concat_variable2 = var2Parser.GetFullValue(x, thisbugview.myTable); if (var2Parser.hasDataLoopVar) { ThisAction.Variable2 = concat_variable2; if ("".equals(ThisAction.Variable2)) { ThisAction.Variable2 = " "; } } try { try { Thread.sleep(totalpause); } catch (Exception ex) { System.out.println("Exception when sleeping: " + ex.toString()); } ThisAction.RunAction(driver); ThisAction.Variable1 = original_value1; ThisAction.Variable2 = original_value2; } catch (Exception ex) { ThisAction.Variable1 = original_value1; ThisAction.Variable2 = original_value2; driver.close(); driver.quit(); SiteTest.setCursor(Cursor.getDefaultCursor()); break; } } } else { ThisAction.Pass = true; } } } } driver.close(); driver.quit(); ArrayList<ActionView> ActionView = thisbugview.ActionsViewList; int ActionIndex = 0; for (ActionView TheseActionViews : ActionView) { LocalDateTime stringtime = bugtorun.ActionsList.get(ActionIndex).TimeOfTest; boolean TestState = bugtorun.ActionsList.get(ActionIndex).Pass; if (TestState == true) { thisbugview.ActionsViewList.get(ActionIndex).JLabelPassFail.setText("Passed at " + stringtime); } else { thisbugview.ActionsViewList.get(ActionIndex).JLabelPassFail.setText("Fail at " + stringtime); } ActionIndex++; } }