List of usage examples for org.openqa.selenium WebDriver manage
Options manage();
From source file:com.wikia.webdriver.pageobjectsfactory.pageobject.WikiBasePageObject.java
License:Open Source License
public void logOut(WebDriver driver) { try {//from w w w . j av a 2s . c o m driver.manage().deleteAllCookies(); driver.get(Global.DOMAIN + URLsContent.LOGOUT); } catch (TimeoutException e) { PageObjectLogging.log("logOut", "page loads for more than 30 seconds", true); } waitForElementPresenceByBy(LOGIN_BUTTON_CSS); PageObjectLogging.log("logOut", "user is logged out", true, driver); }
From source file:com.worldline.easycukes.selenium.pages.PageManager.java
License:Open Source License
/** * Allows to initialize this instance of {@link PageManager} by creating the * {@link WebDriver}/*from w w w. ja v a 2s. co m*/ * * @throws Exception */ public static void initialize() throws Exception { EasyCukesConfiguration<SeleniumConfigurationBean> configuration = new EasyCukesConfiguration<>( SeleniumConfigurationBean.class); if (configuration.isProxyNeeded()) configuration.configureProxy(); if (page.get() == null) { String browserName = ExecutionContext.get("browserName"); if (browserName == null) browserName = configuration.getValues().selenium != null ? configuration.getValues().selenium.getTarget_browser() : "firefox"; WebDriver driver = null; if (configuration.getValues().selenium != null && !configuration.getValues().selenium.isUse_remote()) driver = WebDriverFactory.newLocalWebDriver(browserName); else try { driver = WebDriverFactory.newRemoteWebDriver(browserName); } catch (final Exception e) { log.warn("Setup : " + e.getMessage()); driver = WebDriverFactory.newLocalWebDriver(browserName); } driver.manage().window().maximize(); page.set(new Page(driver)); } }
From source file:com.zaizi.automation.alfresco.core.elements.Element.java
License:Open Source License
/** * Check if the element is present in the page * /*from w w w . jav a2 s.co m*/ * @param driver * @param xPath * @throws InterruptedException */ public static Boolean isElementPresent(WebDriver driver, By xPath) throws InterruptedException { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); try { driver.findElement(xPath); return true; } catch (Exception e) { return false; } finally { driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); } }
From source file:com.zutubi.pulse.acceptance.SeleniumBrowser.java
License:Apache License
public SeleniumBrowser(int port, WebDriver webDriver) { this.webDriver = webDriver; webDriver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS); String baseUrl = AcceptanceTestUtils.getPulseUrl(port); selenium = new WebDriverBackedSelenium(webDriver, baseUrl); this.pulsePort = port; urls = new Urls(baseUrl); }
From source file:com.zywee.tools.WaitTool.java
License:Open Source License
public static WebElement waitForElementChange(WebDriver driver, final By by, int timeOutInSeconds) { WebElement element;/*w w w .ja v a 2s . c om*/ try { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); // nullify // implicitlyWait() new WebDriverWait(driver, timeOutInSeconds) { }.until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver driverObject) { return isElementPresentAndDisplay(driverObject, by); } }); element = driver.findElement(by); driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); // reset // implicitlyWait return element; // return the element } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:conexiones.HTMLData.java
private static int dataContaduria(Expediente exp, Estados estado) { WebDriver driver = new HtmlUnitDriver(); try {/* w w w . ja v a 2s . co m*/ driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.get(URL_CONTADURIA); driver.findElement(By.id("ctl00_ContentPlaceHolder1_tbCaratula")).clear(); driver.findElement(By.id("ctl00_ContentPlaceHolder1_tbCaratula")).sendKeys(exp.getCaratula()); driver.findElement(By.id("ctl00_ContentPlaceHolder1_tbNumero")).clear(); driver.findElement(By.id("ctl00_ContentPlaceHolder1_tbNumero")).sendKeys(exp.getNumero()); driver.findElement(By.id("ctl00_ContentPlaceHolder1_tbAnio")).clear(); driver.findElement(By.id("ctl00_ContentPlaceHolder1_tbAnio")).sendKeys(exp.getAnio()); driver.findElement(By.id("ctl00_ContentPlaceHolder1_tbAlcance")).clear(); driver.findElement(By.id("ctl00_ContentPlaceHolder1_tbAlcance")).sendKeys(exp.getAlcance()); driver.findElement(By.id("ctl00_ContentPlaceHolder1_btnConsultar")).submit(); driver.manage().timeouts().implicitlyWait(100, TimeUnit.NANOSECONDS); try { estado.setEstado(driver.findElement(By.id("lblJur")).getText()); estado.setFechaCon(driver.findElement(By.id("lblEgreFecha")).getText()); estado.setFechaE(estado.getFechaCon()); estado.setPagina(""); return EXP_ENCONTRADO; } catch (NoSuchElementException e) { try { //el expediente esta en contaduria. estado.setEstado( driver.findElement(By.id("ctl00_ContentPlaceHolder1_lblOficinaActual")).getText()); estado.setFechaR( driver.findElement(By.id("ctl00_ContentPlaceHolder1_lblFechaIngreso")).getText()); estado.setPagina("Contaduria"); return EXP_ENCONTRADO; } catch (NoSuchElementException ex) { return EXP_NO_ENCONTRADO; //No se encontro el expediente } } } catch (Exception ex) { return ERROR_PAGINA; //No es posible acceder a la pagina } finally { driver.quit(); } }
From source file:connect.Connector.java
public static WebDriver init(String BrowserName) throws IOException { System.out.println(readFile().getProperty(BrowserName)); if (readFile().getProperty(BrowserName).contains("chrome")) { System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "\\src\\driver\\chromedriver.exe"); driver = new ChromeDriver(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); }//w ww .j a va 2 s . c o m if (BrowserName.contains("Firefox")) { WebDriver driver = new FirefoxDriver(); } return driver; }
From source file:crawling.SeleniumDemo.java
private boolean isElementPresent(WebDriver driver, By by) { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); try {/*from www .j a v a 2 s.c o m*/ driver.findElement(by); return true; } catch (NoSuchElementException e) { return false; } finally { driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); } }
From source file:cucumber.scratch.maven.react.SeleniumConfiguration.java
License:Apache License
@Autowired public void configureWebDriver(WebDriver driver) { driver.manage().timeouts().setScriptTimeout(10, TimeUnit.SECONDS); }
From source file:cuenen.raymond.svgplot.DocumentScalerTest.java
License:CDDL license
/** * Test the scaling of the SVGDocument.//w ww . j av a 2 s.com * * @param driver The WebDriver executing the test. */ @Test(dataProvider = "driver", groups = "all") public void documentScalerTest(WebDriver driver) { Wait wait = load(driver, MODULE_LOADER_SCALER, 1); wait.until(RESULT_SET); WebElement circle = getElementById(driver, PLACEHOLDER_ID); String before = circle.getAttribute("before"); String after = circle.getAttribute("after"); String msg = getMessage(driver); assertNotEquals(before, after, msg); Capabilities caps = ((HasCapabilities) driver).getCapabilities(); Rectangle2D beforeRect = getBeforeRect(caps); assertEquals(toRect(before), beforeRect, msg); String[] size = getResult(driver).split(","); Rectangle2D afterRect = createRect(Double.parseDouble(size[0]), Double.parseDouble(size[1])); if ("opera".equals(caps.getBrowserName())) { afterRect.setRect(Math.floor(afterRect.getX()), Math.floor(afterRect.getY()), Math.floor(afterRect.getWidth()), Math.floor(afterRect.getHeight())); } Rectangle2D expected = toRect(after); if ("firefox".equals(caps.getBrowserName())) { /* Don't know how firefox comes op with its position coordinates. */ Dimension dim = driver.manage().window().getSize(); assertTrue(Double.compare(0.25 * dim.getHeight() - 17.75, afterRect.getY()) == 0); assertTrue(Double.compare(0.5 * dim.getHeight() - 35.5, afterRect.getWidth()) == 0); assertTrue(Double.compare(0.5 * dim.getHeight() - 35.5, afterRect.getHeight()) == 0); } else { assertEquals(expected, afterRect, msg); } }