List of usage examples for org.openqa.selenium.firefox FirefoxBinary FirefoxBinary
public FirefoxBinary(File pathToFirefoxBinary)
From source file:com.vaadin.testbench.parallel.setup.LocalDriver.java
/** * Creates a {@link WebDriver} instance used for running the test locally * for debug purposes./*from ww w . ja v a 2 s.c o m*/ */ 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:de.ppi.selenium.browser.DefaultWebDriverFactory.java
License:Apache License
/** * * @param filePath the binary path location of the firefox app (where it's * installed)/*from www .ja v a2s. c o m*/ * @return */ private static FirefoxBinary getFFBinary(String filePath) { File[] possibleLocations = { new File(filePath != null ? filePath : ""), new File("C:\\Program Files\\Mozilla Firefox\\firefox.exe"), new File("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"), }; File ffbinary = null; for (File curr : possibleLocations) { if (curr.exists()) { ffbinary = curr; break; } } if (ffbinary == null) { throw new RuntimeException("Unable to find firefox binary, please ensure that firefox is installed " + "on your system. If it is then please determine the path to your firefox.exe and set it as " + "binaryPath=<FIREFOX PATH HERE>"); } else { return new FirefoxBinary(ffbinary); } }
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//ww w.j av a 2 s . co 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.ClickminerCLI.java
License:Open Source License
private static void run(String[] args) { GnuParser parser = new GnuParser(); Options opts = ClickminerCLI.initializeOptions(); CommandLine cli;/*from w ww . ja va 2 s. co m*/ RemoteWebDriver wdriver = null; try { cli = parser.parse(opts, args); if (cli.hasOption('?')) { throw new ParseException(null); } if (log.isInfoEnabled()) { StringBuffer arginfo = new StringBuffer("\n"); arginfo.append("firefox-binary: " + cli.getOptionValue('b') + "\n"); arginfo.append("firefox-profile: " + cli.getOptionValue('P') + "\n"); arginfo.append("host: " + cli.getOptionValue('h') + "\n"); arginfo.append("proxy-port: " + cli.getOptionValue('p') + "\n"); arginfo.append("inst-server-port: " + cli.getOptionValue('q') + "\n"); arginfo.append("clicklog: " + cli.getOptionValue('o') + "\n"); arginfo.append("check-limit: " + cli.getOptionValue('l') + "\n"); String[] mimes = cli.getOptionValues('f'); String mimesstr = null; if (mimes != null) { mimesstr = new String(); for (int i = 0; i < mimes.length; i++) { if (i < mimes.length - 1) { mimesstr += mimes[i] + ","; } else { mimesstr += mimes[i]; } } } arginfo.append("filter-mime: " + mimesstr + "\n"); arginfo.append("javascript-execution: " + cli.hasOption('j') + "\n"); arginfo.append("flash: " + cli.hasOption('F') + "\n"); arginfo.append("unstable-loading: " + cli.hasOption('u') + "\n"); arginfo.append("firefox-stdio-log: " + cli.getOptionValue("Lo") + "\n"); arginfo.append("firefox-webdriver-log: " + cli.getOptionValue("Ld") + "\n"); log.info(arginfo.toString()); } String binarypath = cli.getOptionValue('b'); FirefoxBinary binary = null; if (binarypath != null) { binary = new FirefoxBinary(new File(binarypath)); } Pair<DesiredCapabilities, FirefoxProfile> config = createBrowserConfig(cli); wdriver = new FirefoxDriver(binary, config.getRight(), config.getLeft()); if (cli.hasOption("u")) { wdriver.manage().timeouts().pageLoadTimeout(1000, TimeUnit.MILLISECONDS); wdriver.manage().timeouts().implicitlyWait(1000, TimeUnit.MILLISECONDS); } ProxyClient pc = new ProxyClient(cli.getOptionValue('h'), ((Number) cli.getParsedOptionValue("q")).intValue()); if (cli.hasOption('l')) { pc.setRequestCheckLimit(((Number) cli.getParsedOptionValue("l")).intValue()); } if (cli.hasOption('f')) { List<String> types = Arrays.asList(cli.getOptionValues('f')); pc.setFilteredResponseType(types); } BrowserEngine bengine = new BrowserEngine(pc, wdriver, cli.hasOption('j'), cli.hasOption('F')); try { bengine.run(); } catch (Exception e) { if (log.isFatalEnabled()) { log.fatal("", e); } } List<InteractionRecord> ilog = bengine.getInteractionLog(); JSONWriter<InteractionRecord> writer = new JSONWriter<InteractionRecord>(); try { writer.write(new File(cli.getOptionValue('o')), ilog); } catch (Exception e) { if (log.isErrorEnabled()) { log.error("", e); } } bengine.close(); } catch (ParseException e1) { PrintWriter writer = new PrintWriter(System.out); HelpFormatter usageFormatter = new HelpFormatter(); usageFormatter.printHelp(writer, 80, "clickminer", "", opts, 0, 2, ""); writer.close(); } catch (ProxyErrorException e2) { String message = "Error communicating with proxy server. Aborting"; if (log.isFatalEnabled()) { log.fatal(message, e2); } } finally { if (wdriver != null) { try { wdriver.close(); } catch (Exception e) { if (log.isDebugEnabled()) { log.debug(e); } System.exit(-1); } } } }
From source file:edu.uga.cs.clickminer.test.BrowserEngineTest.java
License:Open Source License
/** * <p>browserEngineTest_5.</p> *//*from www . ja va 2 s .c o m*/ public static void browserEngineTest_5() { ProxyClient pc = new ProxyClient("127.0.0.1", 8888); FirefoxProfile profile = new FirefoxProfile( TestUtils.getWebdriverProfile("/home/cjneasbi/.mozilla/firefox", "webdriver")); profile.setEnableNativeEvents(true); RemoteWebDriver wdriver = new FirefoxDriver( new FirefoxBinary(new File("/home/cjneasbi/Desktop/old_firefox/firefox-12/firefox")), profile, TestUtils.createProxyConfig()); BrowserEngine bengine = new BrowserEngine(pc, wdriver); bengine.run(); List<InteractionRecord> ilog = bengine.getInteractionLog(); JSONWriter<InteractionRecord> writer = new JSONWriter<InteractionRecord>(); try { writer.write(new File("/home/cjneasbi/Desktop/ilog.json"), ilog); } catch (Exception e) { if (log.isErrorEnabled()) { log.error("", e); } } bengine.close(); }
From source file:edu.uga.cs.clickminer.test.BrowserEngineTest.java
License:Open Source License
/** * <p>browserEngineTest_9.</p> *///from www .j ava2 s . c om public static void browserEngineTest_9() { 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, TestUtils.createProxyConfig()); ProxyClient pc = new ProxyClient("127.0.0.1", 8888); BrowserEngine bengine = new BrowserEngine(pc, wdriver); try { bengine.run(); } catch (Exception e) { e.printStackTrace(); } List<InteractionRecord> ilog = bengine.getInteractionLog(); JSONWriter<InteractionRecord> writer = new JSONWriter<InteractionRecord>(); try { writer.write(new File("/home/cjneasbi/Desktop/mined_clicks.json"), ilog); } catch (Exception e) { if (log.isErrorEnabled()) { log.error("", e); } } bengine.close(); }
From source file:edu.uga.cs.clickminer.test.BrowserEngineTest.java
License:Open Source License
/** * <p>browserEngineTest_12.</p> *//*from w w w .ja v a2 s . c o m*/ public static void browserEngineTest_12() { 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, TestUtils.createProxyConfig()); ProxyClient pc = new ProxyClient("127.0.0.1", 8888); BrowserEngine bengine = new BrowserEngine(pc, wdriver, true, true); try { bengine.run(); } catch (Exception e) { e.printStackTrace(); } List<InteractionRecord> ilog = bengine.getInteractionLog(); JSONWriter<InteractionRecord> writer = new JSONWriter<InteractionRecord>(); try { writer.write(new File("/home/cjneasbi/Desktop/mined_clicks_js.json"), ilog); } catch (Exception e) { if (log.isErrorEnabled()) { log.error(e); } } bengine.close(); }
From source file:edu.uga.cs.clickminer.test.BrowserEngineTest.java
License:Open Source License
/** * <p>browserEngineTest_13.</p> * * @throws edu.uga.cs.clickminer.exception.ProxyErrorException if any. *//* ww w. jav a 2 s . co m*/ public static void browserEngineTest_13() throws ProxyErrorException { 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, TestUtils.createProxyConfig()); ProxyClient pc = new ProxyClient("127.0.0.1", 8888); pc.setRequestCheckLimit(3); BrowserEngine bengine = new BrowserEngine(pc, wdriver); try { bengine.run(); } catch (Exception e) { e.printStackTrace(); } List<InteractionRecord> ilog = bengine.getInteractionLog(); JSONWriter<InteractionRecord> writer = new JSONWriter<InteractionRecord>(); try { writer.write(new File("/home/cjneasbi/Desktop/mined_clicks.json"), ilog); } catch (Exception e) { if (log.isErrorEnabled()) { log.error("", e); } } bengine.close(); }
From source file:edu.uga.cs.clickminer.test.BrowserEngineTest.java
License:Open Source License
/** * <p>browserEngineTest_14.</p> * * @throws edu.uga.cs.clickminer.exception.ProxyErrorException if any. */// w w w . java 2 s .c om public static void browserEngineTest_14() throws ProxyErrorException { 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, TestUtils.createProxyConfig()); ProxyClient pc = new ProxyClient("127.0.0.1", 8888); pc.setRequestCheckLimit(3); BrowserEngine bengine = new BrowserEngine(pc, wdriver, true, true); try { bengine.run(); } catch (Exception e) { e.printStackTrace(); } List<InteractionRecord> ilog = bengine.getInteractionLog(); JSONWriter<InteractionRecord> writer = new JSONWriter<InteractionRecord>(); try { writer.write(new File("/home/cjneasbi/Desktop/mined_clicks_js.json"), ilog); } catch (Exception e) { if (log.isErrorEnabled()) { log.error("", e); } } bengine.close(); }
From source file:edu.uga.cs.clickminer.test.BrowserEngineTest.java
License:Open Source License
/** * <p>browserEngineTest_15.</p> *//*from w w w. j a va2s . 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(); }