List of usage examples for org.openqa.selenium.remote RemoteWebDriver manage
@Override
public Options manage()
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;// ww w. j a v a 2s . c om 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:org.asqatasun.sebuilder.interpreter.webdriverfactory.FirefoxDriverFactory.java
License:Open Source License
/** * // ww w. j ava 2s . co m * @param config * @return A FirefoxDriver. */ @Override public RemoteWebDriver make(HashMap<String, String> config) { FirefoxBinary ffBinary = new FirefoxBinary(); if (System.getProperty(DISPLAY_PROPERTY) != null) { ffBinary.setEnvironmentProperty(DISPLAY_PROPERTY.toUpperCase(), System.getProperty(DISPLAY_PROPERTY)); } else if (System.getenv(DISPLAY_PROPERTY.toUpperCase()) != null) { ffBinary.setEnvironmentProperty(DISPLAY_PROPERTY.toUpperCase(), System.getenv(DISPLAY_PROPERTY.toUpperCase())); } RemoteWebDriver remoteWebDriver = new FirefoxDriver(ffBinary, firefoxProfile); if (screenHeight != -1 && screenWidth != -1) { remoteWebDriver.manage().window().setSize(new Dimension(screenWidth, screenHeight)); } return remoteWebDriver; }
From source file:org.asqatasun.websnapshot.service.SnapshotCreatorImpl.java
License:Open Source License
/** * * @return//from www . j a v a 2s . c om */ private RemoteWebDriver getWebDriver(int windowWidth, int windowHeight, String webDriver) { RemoteWebDriver driver; if (webDriver.equals(FIREFOX_BROWSER_NAME)) { driver = new FirefoxDriver(new FirefoxBinary(new File(firefoxBinaryPath)), new FirefoxProfile()); } else { DesiredCapabilities caps = DesiredCapabilities.phantomjs(); caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomJsBinaryPath); driver = new PhantomJSDriver(caps); } driver.manage().window().setSize(new Dimension(windowWidth, windowHeight)); return driver; }
From source file:org.callimachusproject.webdriver.helpers.BrowserFunctionalTestCase.java
License:Apache License
private void init(RemoteWebDriver driver) { try {/*from w w w . j ava2 s .co m*/ driver.setFileDetector(new LocalFileDetector()); } catch (WebDriverException e) { // ignore } int wait = WebBrowserDriver.IMPLICITLY_WAIT; driver.manage().timeouts().implicitlyWait(wait, TimeUnit.SECONDS); driver.manage().timeouts().setScriptTimeout(wait, TimeUnit.SECONDS); driver.navigate().to(getStartUrl()); }
From source file:org.eclipse.che.selenium.core.SeleniumWebDriver.java
License:Open Source License
private RemoteWebDriver doCreateDriver(URL webDriverUrl) { DesiredCapabilities capability;//from w ww . j av a 2s.com switch (browser) { case GOOGLE_CHROME: LoggingPreferences loggingPreferences = new LoggingPreferences(); loggingPreferences.enable(LogType.PERFORMANCE, Level.ALL); loggingPreferences.enable(LogType.BROWSER, Level.ALL); ChromeOptions options = new ChromeOptions(); options.addArguments("--no-sandbox"); options.addArguments("--dns-prefetch-disable"); options.addArguments("--ignore-certificate-errors"); // set parameters required for automatic download capability Map<String, Object> chromePrefs = new HashMap<>(); chromePrefs.put("download.default_directory", downloadDir); chromePrefs.put("download.prompt_for_download", false); chromePrefs.put("download.directory_upgrade", true); chromePrefs.put("safebrowsing.enabled", true); chromePrefs.put("profile.default_content_settings.popups", 0); chromePrefs.put("plugins.plugins_disabled", "['Chrome PDF Viewer']"); options.setExperimentalOption("prefs", chromePrefs); capability = DesiredCapabilities.chrome(); capability.setCapability(ChromeOptions.CAPABILITY, options); capability.setCapability(CapabilityType.LOGGING_PREFS, loggingPreferences); capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); break; default: capability = DesiredCapabilities.firefox(); capability.setCapability("dom.max_script_run_time", 240); capability.setCapability("dom.max_chrome_script_run_time", 240); } RemoteWebDriver driver = new RemoteWebDriver(webDriverUrl, capability); if (driver.getErrorHandler().isIncludeServerErrors() && driver.getCapabilities().getCapability("message") != null) { String errorMessage = format("Web driver creation error occurred: %s", driver.getCapabilities().getCapability("message")); LOG.error(errorMessage); throw new RuntimeException(errorMessage); } driver.manage().window().setSize(new Dimension(1920, 1080)); return driver; }
From source file:org.polimi.zarathustra.webdriver.WebdriverWorker.java
License:Open Source License
@VisibleForTesting WebdriverWorker(RemoteWebDriver infectedDriver, RemoteWebDriver clearDriver, RemoteWebDriver cleanTestDriver) { this.infectedDriver = Preconditions.checkNotNull(infectedDriver); this.cleanDriver = Preconditions.checkNotNull(clearDriver); this.cleanTestDriver = Preconditions.checkNotNull(cleanTestDriver); infectedDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); cleanDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); cleanTestDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); }
From source file:org.uiautomation.ios.Demo.java
License:Apache License
public static void main(String[] args) throws Exception { String[] a = { "-port", "5555", "-host", "127.0.0.1", //"-aut", SampleApps.getUICatalogFile(), //"-aut", SampleApps.getUICatalogIpad(), //"-beta", "-folder", "applications", "-simulators", "-hub", "http://127.0.0.1:4444/grid/register" }; IOSServerConfiguration config = IOSServerConfiguration.create(a); IOSServer server = new IOSServer(config); server.start();//from w w w . j a va2s. c om IOSCapabilities cap = IOSCapabilities.iphone("eBay"); cap.setCapability(IOSCapabilities.IOS_SWITCHES, Arrays.asList(new String[] { "-e", "useQA", "YES" })); RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), cap); try { driver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS); WebElement agree = driver.findElement(By.name("Agree")); agree.click(); //driver.switchTo().alert().dismiss(); WebElement signInButton = driver.findElement(By.xpath("//UIAButton[@name='Sign In']")); signInButton.click(); WebElement user = driver.findElement(By.xpath("//UIATextField[@value='User ID or email']")); user.sendKeys(userId); WebElement pass = driver.findElement(By.xpath("//UIASecureTextField[@value='Password']")); pass.sendKeys(password); WebElement element4 = driver.findElement(By.xpath("//UIAButton[@name='Done']")); element4.click(); Thread.sleep(2000); boolean cartDown = false; // navigate String itemId = "220003725262"; if (cartDown) { WebElement search = driver.findElement(By.xpath("//UIAButton[@name='Search']")); search.click(); //validate WebElement element1 = driver.findElement(By.xpath("//UIASearchBar[@value='Search Watching']")); element1.sendKeys(itemId); // check it's there. WebElement result = driver.findElement(By.className("UIATableCell")); System.out.println(result.getAttribute("name")); } else { WebElement basket = driver.findElement(By.xpath("//UIAButton[@name='Basket, 1 item']")); //By.xpath("//UIAButton[matches(@name,l10n('ItemCountFormatStringPlural'))]")); //ItemCountFormatStringSingular basket.click(); //WebElement firstItem = driver.findElement(By.xpath("//UIATableCell[2]")); //firstItem.click(); WebElement search = driver.findElement(By.name("Checkout")); search.click(); } // watch WebElement paypal = driver.findElement(By.name("Please login to your account")); paypal.click(); while (driver.getWindowHandles().size() != 3) { Thread.sleep(1000); } WebElement email = null; while (email == null) { try { driver.switchTo().window("Web_3"); email = driver.findElement(By.id("email")); } catch (NoSuchElementException e) { Thread.sleep(1000); System.out.println("not found"); } } driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS); driver.findElement(By.cssSelector(".resetter")).click(); email.sendKeys("ppbuild-1920977828325914@paypal.com"); WebElement password = driver.findElement(By.id("password")); password.sendKeys("11111111"); WebElement login = driver.findElement(By.id("login")); login.click(); Thread.sleep(30000); } finally { driver.quit(); server.stop(); } }