List of usage examples for org.openqa.selenium.firefox FirefoxDriver FirefoxDriver
private FirefoxDriver(FirefoxDriverCommandExecutor executor, FirefoxOptions options)
From source file:com.googlesites.SanityTests.java
@BeforeClass public void before() { driver = new FirefoxDriver(new FirefoxBinary(new File(Config.getPropertyValue("firefoxLocation"))), profile);//from w w w. java 2 s . co m driver.manage().window().maximize(); WebDriverInstance wdi = new WebDriverInstance(); wdi.setCurrentDriver(driver); }
From source file:com.googlesites.WebDriverInstance.java
public static WebDriver startDriver() { driver = new FirefoxDriver(new FirefoxBinary(new File(Config.getPropertyValue("firefoxLocation"))), profile);/*from ww w .ja v a2 s . c o m*/ return driver; }
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 {/*from w w w . j a v a 2s . c o m*/ return new FirefoxDriver(firefoxProfile); } }
From source file:com.sugarcrm.candybean.automation.VInterface.java
License:Open Source License
private WebDriver getWebDriver(Type iType) throws Exception { DesiredCapabilities capabilities = new DesiredCapabilities(); // capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT); WebDriver wd = null;//w w w .j a v a2 s . c o m switch (iType) { case FIREFOX: String profileName = this.config.getValue("browser.firefox_profile", "default"); File ffBinaryPath = new File(this.config.getPathValue("browser.firefox_binary")); FirefoxProfile ffProfile = (new ProfilesIni()).getProfile(profileName); // ffProfile.setEnableNativeEvents(false); FirefoxBinary ffBinary = new FirefoxBinary(ffBinaryPath); // if (System.getProperty("headless") != null) { // FirefoxBinary ffBinary = new FirefoxBinary();//new // File("//home//conrad//Applications//firefox-10//firefox")); // ffBinary.setEnvironmentProperty("DISPLAY", ":1"); // webDriver = new FirefoxDriver(ffBinary, ffProfile); // } candybean.log.info("Instantiating Firefox with profile name: " + profileName + " and binary path: " + ffBinaryPath); wd = new FirefoxDriver(ffBinary, ffProfile); break; case CHROME: ChromeOptions chromeOptions = new ChromeOptions(); String chromeDriverLogPath = this.config.getPathValue("browser.chrome_driver_log_path"); candybean.log.info("chromeDriverLogPath: " + chromeDriverLogPath); chromeOptions.addArguments("--log-path=" + chromeDriverLogPath); String chromeDriverPath = this.config.getPathValue("browser.chrome_driver_path"); candybean.log.info("chromeDriverPath: " + chromeDriverPath); // chromeOptions.setBinary(new File(chromeDriverPath)); System.setProperty("webdriver.chrome.driver", chromeDriverPath); candybean.log.info("Instantiating Chrome with:\n log path:" + chromeDriverLogPath + "\n driver path: " + chromeDriverPath); wd = new ChromeDriver(chromeOptions); break; case IE: String ieDriverPath = this.config.getPathValue("browser.ie_driver_path"); candybean.log.info("ieDriverPath: " + ieDriverPath); System.setProperty("webdriver.ie.driver", ieDriverPath); capabilities = DesiredCapabilities.internetExplorer(); wd = new InternetExplorerDriver(capabilities); break; case SAFARI: throw new Exception("Selenium: safari browser not yet supported."); case ANDROID: capabilities = new DesiredCapabilities(); capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android"); capabilities.setCapability(CapabilityType.PLATFORM, "Mac"); capabilities.setCapability("app", "https://s3.amazonaws.com/voodoo2/ApiDemos-debug.apk"); wd = new SwipeableWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); break; case IOS: capabilities = new DesiredCapabilities(); capabilities.setCapability(CapabilityType.BROWSER_NAME, "iOS"); capabilities.setCapability(CapabilityType.VERSION, "6.0"); capabilities.setCapability(CapabilityType.PLATFORM, "Mac"); capabilities.setCapability("app", "https://s3.amazonaws.com/voodoo2/TestApp.zip"); wd = new SwipeableWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); break; default: throw new Exception("Selenium: browser type not recognized."); } long implicitWait = Long.parseLong(config.getValue("perf.implicit_wait_seconds")); if (System.getProperty("headless") == null) { java.awt.Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); wd.manage().window().setSize(new Dimension(screenSize.width, screenSize.height)); } wd.manage().timeouts().implicitlyWait(implicitWait, TimeUnit.SECONDS); return wd; }
From source file:com.vaadin.testbench.parallel.setup.LocalDriver.java
/** * Creates a {@link WebDriver} instance used for running the test locally * for debug purposes.// w ww .ja v a2 s. com */ static public WebDriver createDriver(DesiredCapabilities desiredCapabilities) { WebDriver driver; if (BrowserUtil.isFirefox(desiredCapabilities)) { String firefoxPath = System.getProperty("firefox.path"); String profilePath = System.getProperty("firefox.profile.path"); if (firefoxPath != null) { if (profilePath != null) { File profileDir = new File(profilePath); FirefoxProfile profile = new FirefoxProfile(profileDir); driver = new FirefoxDriver(new FirefoxBinary(new File(firefoxPath)), profile); } else { driver = new FirefoxDriver(new FirefoxBinary(new File(firefoxPath)), null); } } else { driver = new FirefoxDriver(); } } else if (BrowserUtil.isChrome(desiredCapabilities)) { // Tells chrome not to show warning // "You are using an unsupported command-line flag: --ignore-certifcate-errors". // #14319 ChromeOptions options = new ChromeOptions(); options.addArguments("--test-type "); driver = new ChromeDriver(options); } else if (BrowserUtil.isSafari(desiredCapabilities)) { driver = new SafariDriver(); } else if (BrowserUtil.isPhantomJS(desiredCapabilities)) { driver = new PhantomJSDriver(); } else { throw new RuntimeException( "Not implemented support for running locally on " + desiredCapabilities.getBrowserName()); } return TestBench.createDriver(driver); }
From source file:com.yufei.dataget.dataretriver.HttpDataRetriverUsingFirefoxDriver.java
@Override public void connect() { FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("permissions.default.stylesheet", 2); profile.setPreference("permissions.default.image", 2); profile.setPreference("dom.ipc.plugins.enabled.libflashplayer.so", "false"); //profile.setPreference("DISPLAY", ":10"); FirefoxBinary fb = new FirefoxBinary(); fb.setEnvironmentProperty("DISPLAY", ":10"); // sudo Xvfb :10 -ac driver = new FirefoxDriver(fb, profile); driver.get(this.url.toString()); }
From source file:DerpSelenium.test.java
public static void loginMega(String username, String passwd) throws InterruptedException { FirefoxProfile profile = new FirefoxProfile(); WebDriver driver = new FirefoxDriver(new FirefoxBinary(new File("/home/michael/bin/firefox")), profile); driver.get("http://www.mega.nz"); (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { @Override/*from ww w .j a va 2 s. c o m*/ public Boolean apply(WebDriver d) { try { WebElement loginButton = d.findElement(By.className("top-login-button")); System.out.println(loginButton.getText()); } catch (NoSuchElementException e) { return false; } return true; } }); WebElement loginButton = driver.findElement(By.xpath("//a[@class='top-login-button hidden']")); loginButton.click(); WebElement nameElement = driver.findElement(By.name("login-name")); WebElement pwElement = driver.findElement(By.name("login-password")); nameElement.sendKeys(username); pwElement.sendKeys(passwd); WebElement submitButton = driver.findElement(By.className("top-dialog-login-button")); submitButton.click(); Thread.sleep(15000); String url = driver.getCurrentUrl(); List<WebElement> elements = driver.findElements(By.tagName("div")); Map<String, WebElement> elementMap = new HashMap<>(); for (Iterator<WebElement> it = elements.iterator(); it.hasNext();) { WebElement e = it.next(); try { if (!e.isDisplayed() || !e.isEnabled() || e.getAttribute("class").equals("")) { it.remove(); } else { elementMap.put(e.getAttribute("class"), e); } } catch (StaleElementReferenceException ex) { it.remove(); } } print("Number of added elements = " + elements.size()); List<WebElement> contacts = driver .findElements(By.xpath("//div[@class='nw-fm-left-icon contacts ui-droppable']")); contacts.get(1).click(); Thread.sleep(2000); //driver.navigate().back(); //Thread.sleep(2000); WebElement el = elementMap.get("nw-fm-left-icon shared-with-me ui-droppable"); if (el == null) { print("Element not found"); } else { el.click(); } }
From source file:edu.uga.cs.clickminer.test.BrowserEngineTest.java
License:Open Source License
/** * <p>browserEngineTest_10.</p> *//*from w ww . java 2 s .c om*/ public static void browserEngineTest_10() { FirefoxProfile profile = new FirefoxProfile( TestUtils.getWebdriverProfile("/home/cjneasbi/.mozilla/firefox", "webdriver")); WebDriver wdriver = new FirefoxDriver(null, profile); wdriver.get("http://www.dkfjaojfko.com"); try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println(wdriver.getCurrentUrl()); System.out.println(wdriver.getTitle()); System.out.println(wdriver.getPageSource()); wdriver.quit(); }
From source file:edu.uga.cs.clickminer.test.BrowserEngineTest.java
License:Open Source License
/** * <p>browserEngineTest_15.</p> *///from ww w . j ava 2 s .c om public static void browserEngineTest_15() { FirefoxProfile profile = new FirefoxProfile( TestUtils.getWebdriverProfile("/home/cjneasbi/.mozilla/firefox", "webdriver")); WebDriver wdriver = new FirefoxDriver( new FirefoxBinary(new File("/home/cjneasbi/Desktop/old_firefox/firefox-14.0.1/firefox-bin")), profile); wdriver.get("http://www.cs.uga.edu/~neasbitt/"); try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } WebElement elem = wdriver.findElement(By.id("logo")); JSUtils.setElementAttribute(wdriver, elem, "id", "logologologo1"); try { elem = wdriver.findElement(By.id("logologologo1")); System.out.println("Pass"); } catch (NoSuchElementException e) { System.out.println("Fail"); } wdriver.close(); }
From source file:edu.uga.cs.clickminer.test.BrowserEngineTest.java
License:Open Source License
/** * <p>browserEngineTest_16.</p> * * @throws java.io.IOException if any./*from w w w . j a va 2s .c om*/ * @throws java.lang.InterruptedException if any. */ public static void browserEngineTest_16() throws IOException, InterruptedException { FirefoxProfile profile = new FirefoxProfile( TestUtils.getWebdriverProfile("/home/cjneasbi/.mozilla/firefox", "webdriver")); WebDriver wdriver = new FirefoxDriver( new FirefoxBinary(new File("/home/cjneasbi/Desktop/old_firefox/firefox-17.0/firefox-bin")), profile); // WebDriver wdriver = new FirefoxDriver(); wdriver.get("http://www.cs.uga.edu/~neasbitt/"); wdriver.switchTo().activeElement(); Thread.sleep(10000); WebElement elem = wdriver.findElement(By.id("logo")); List<String> locator = JSUtils.getElementLocator(wdriver, elem); for (String s : locator) { System.out.println(s); } wdriver.close(); }