List of usage examples for org.openqa.selenium.support.ui Wait until
<T> T until(Function<? super F, T> isTrue);
From source file:com.ibm.watson.movieapp.dialog.fvt.webui.BaseUI.java
License:Open Source License
/** * fluentWaitVisible -//from w ww.j ava 2s .co m * @param locator * @return */ public boolean fluentWaitVisible(final String locator) { logger.info("INFO: Fluentwait for visibility of element: " + locator); Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(TIMEOUT, TimeUnit.SECONDS) .pollingEvery(POLL, TimeUnit.SECONDS).ignoring(NoSuchElementException.class); boolean found = wait.until(new Function<WebDriver, Boolean>() { public Boolean apply(WebDriver driver) { boolean elementPresent = false; if (!elementPresent) { elementPresent = findElement(locator).isDisplayed(); } return elementPresent; } }); return found; }
From source file:com.ibm.watson.movieapp.dialog.fvt.webui.BaseUI.java
License:Open Source License
/** * fluentWaitVisibleRefresh -// w w w .j a v a2 s .com * @param locator * @return */ public boolean fluentWaitVisibleRefresh(final String locator) { logger.info("INFO: Fluentwait for visibility of element: " + locator); Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(TIMEOUT, TimeUnit.SECONDS) .pollingEvery(POLL, TimeUnit.SECONDS).ignoring(NoSuchElementException.class); boolean found = wait.until(new Function<WebDriver, Boolean>() { public Boolean apply(WebDriver driver) { boolean elementPresent = false; if (!elementPresent) { elementPresent = findElement(locator).isDisplayed(); driver.navigate().refresh(); } return elementPresent; } }); return found; }
From source file:com.ibm.watson.movieapp.dialog.fvt.webui.BaseUI.java
License:Open Source License
/** * fluentWaitAttrChange - Method to wait for attribute change * @param locator - Use .attribute()//w ww.ja v a2s .co m * @see fluentWaitPresent(final WebElement element) * @return */ public boolean fluentWaitAttrChange(final String locator, final String attrib, final String value) { logger.info("INFO: Fluentwait for " + locator + " " + attrib + " to change to " + value); Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(TIMEOUT, TimeUnit.SECONDS) .pollingEvery(POLL, TimeUnit.SECONDS).ignoring(NoSuchElementException.class); boolean foo = wait.until(new Function<WebDriver, Boolean>() { public Boolean apply(WebDriver driver) { WebElement element = findElement(locator); String attribValue = element.getAttribute(attrib); logger.info("INFO: Current Attribute value: " + attribValue); return attribValue.contains(value); } }); return foo; }
From source file:com.ionidea.RegressionNGA.Tests.util.DriverExtension.java
public void waitForPageLoaded(WebDriver driver, int standartWaitTime) { ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver driver) { return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete"); }//from w w w . ja v a 2s .c o m }; Wait<WebDriver> wait = new WebDriverWait(driver, standartWaitTime); try { wait.until(expectation); } catch (Throwable error) { Assert.fail("Timeout waiting for Page Load Request to complete.", error); } }
From source file:com.nuxeo.functionaltests.ITAssetViewTest.java
License:Open Source License
@Test public void testIntellectualProperty() throws Exception { login("leela", "test"); DAMPage damPage = getDAMPage();// www.j a v a 2s . co m damPage = damPage.createAsset("File", "One File", "One File description", "Leela", "1/1/2012"); AssetViewFragment assetViewFragment = damPage.getAssetViewFragment(); FoldableBoxFragment ipBox = assetViewFragment.getFoldableBox("Intellectual Property", true); ipBox.checkTextToBeNotPresent("New holder"); ipBox.edit(); WebElement copyrightHolderInput = driver.findElement( By.id("nxl_gridDamLayout:nxw_damAssetViewIpRights_toggledForm:nxl_ip_rights:nxw_copyright_holder")); copyrightHolderInput.clear(); copyrightHolderInput.sendKeys("New holder"); ipBox.save(); Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(5, TimeUnit.SECONDS) .pollingEvery(100, TimeUnit.MILLISECONDS).ignoring(NoSuchElementException.class); try { wait.until(new Function<WebDriver, WebElement>() { public WebElement apply(WebDriver driver) { return driver .findElement(By.xpath("//div[contains(.,'" + FILE_MODIFIED_NOTIFICATION_LABEL + "')]")); } }); } catch (TimeoutException e) { log.warn("Could not see saved message, maybe I was too slow and it " + "has already disappeared. Let's see if I can restore."); } ipBox.open(); ipBox.waitForTextToBePresent("New holder"); logout(); }
From source file:com.opera.core.systems.NavigationTest.java
License:Apache License
@Test // TODO(andreastt): Should be made local public void testHttpRedirect() { final String fetchedUrl = "http://t/core/bts/javascript/CORE-26410/003-2.php"; driver.navigate().to(fetchedUrl);/*from w w w . j ava2 s. co m*/ // Wait for redirect Wait<WebDriver> wait = new WebDriverWait(driver, OperaIntervals.PAGE_LOAD_TIMEOUT.getValue()); wait.until(new ExpectedCondition<Object>() { public Boolean apply(WebDriver driver) { return !driver.getCurrentUrl().equals(fetchedUrl); } }); assertEquals("http://t/core/bts/javascript/CORE-26410/001-3.php", driver.getCurrentUrl()); }
From source file:com.partnet.automation.HtmlView.java
License:Apache License
/** * Waits for an element to appear on the page before returning. Example: * WebElement waitElement =/*from w ww. j a v a2s.c om*/ * fluentWait(By.cssSelector(div[class='someClass'])); * * @param locator locator of the element to find * @return Web element of found element */ protected WebElement waitForElementToAppear(final By locator) { Wait<WebDriver> wait = new FluentWait<WebDriver>(webDriver).withTimeout(30, TimeUnit.SECONDS) .pollingEvery(5, TimeUnit.SECONDS).ignoring(NoSuchElementException.class); WebElement element = null; try { element = wait.until(new Function<WebDriver, WebElement>() { @Override public WebElement apply(WebDriver driver) { return driver.findElement(locator); } }); } catch (TimeoutException e) { try { // I want the error message on what element was not found webDriver.findElement(locator); } catch (NoSuchElementException renamedErrorOutput) { // print that error message renamedErrorOutput.addSuppressed(e); // throw new // NoSuchElementException("Timeout reached when waiting for element to be found!" // + e.getMessage(), correctErrorOutput); throw renamedErrorOutput; } e.addSuppressed(e); throw new NoSuchElementException("Timeout reached when searching for element!", e); } return element; }
From source file:com.pentaho.ctools.utils.ElementHelper.java
License:Apache License
/** * This method shall wait for the title and return it. The developer can * specify the timeout and pollingTime.//from w w w . j a va2 s. c om * * * @param driver * @param title * @param timeout * @param pollingTime * @return */ public String WaitForTitle(final WebDriver driver, final String title, final Integer timeout, final Integer pollingTime) { this.log.debug("WaitForTitle::Enter"); String returnTitle = ""; driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); ExecutorService executor = null; try { class RunnableObject implements Runnable { private Boolean textIsEquals; public Boolean isTextEquals() { return this.textIsEquals; } @Override public void run() { Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(timeout, TimeUnit.SECONDS) .pollingEvery(pollingTime, TimeUnit.MILLISECONDS); // Wait for element visible this.textIsEquals = wait.until(new Function<WebDriver, Boolean>() { @Override public Boolean apply(WebDriver d) { String currentTitle = driver.getTitle(); return currentTitle != null && currentTitle.contains(title); } }); } } RunnableObject r = new RunnableObject(); executor = Executors.newSingleThreadExecutor(); executor.submit(r).get(timeout + 2, TimeUnit.SECONDS); if (r.isTextEquals()) { // If the text is equals then send the text that we wait for. returnTitle = title; this.log.debug("Wait for text successful!"); } } catch (InterruptedException ie) { this.log.warn("Interrupted Exception"); this.log.warn(ie.toString()); } catch (ExecutionException ee) { if (ee.getCause().getClass().getCanonicalName() .equalsIgnoreCase(TimeoutException.class.getCanonicalName())) { this.log.warn("WebDriver timeout exceeded!"); } else { this.log.warn("Execution Exception"); this.log.warn(ee.toString()); } } catch (java.util.concurrent.TimeoutException cte) { this.log.warn("Thread timeout exceeded!"); this.log.warn(cte.toString()); } catch (Exception e) { this.log.error("Exception"); this.log.catching(e); } if (executor != null) { executor.shutdown(); } driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); this.log.debug("WaitForTitle::Exit"); return returnTitle; }
From source file:com.pentaho.ctools.utils.ElementHelper.java
License:Apache License
/** * This method pretends to check if the element is present, if it doesn't * then don't wait, if element is present, wait for its invisibility. * true - element invisible//from ww w . j a v a 2 s .c o m * false - element visible * @param driver * @param locator * @param timeout */ public boolean WaitForElementInvisibility(final WebDriver driver, final By locator, final Integer timeout) { this.log.debug("WaitForElementInvisibility::Enter"); this.log.debug("Locator: " + locator.toString()); boolean isElemVisible = false; ExecutorService executor = null; try { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); try { class RunnableObject implements Runnable { private boolean isVisible; public boolean getVisibility() { return this.isVisible; } public void run() { Wait<WebDriver> wait = new FluentWait<WebDriver>(driver) .withTimeout(timeout, TimeUnit.SECONDS).pollingEvery(50, TimeUnit.MILLISECONDS); // Wait for element invisible this.isVisible = wait.until(new Function<WebDriver, Boolean>() { @Override public Boolean apply(WebDriver d) { try { List<WebElement> listElements = d.findElements(locator); if (listElements.size() > 0) { WebElement elem = listElements.get(0); return (!elem.isDisplayed()) ? true : false; } // The element does not exit, i.e., is not visible and even present return true; } catch (StaleElementReferenceException sere) { return false; } } }); } } RunnableObject r = new RunnableObject(); executor = Executors.newSingleThreadExecutor(); executor.submit(r).get(timeout + 2, TimeUnit.SECONDS); isElemVisible = r.getVisibility(); } catch (InterruptedException ie) { this.log.warn("Interrupted Exception"); this.log.warn(ie.toString()); } catch (ExecutionException ee) { if (ee.getCause().getClass().getCanonicalName() .equalsIgnoreCase(TimeoutException.class.getCanonicalName())) { this.log.warn("WebDriver timeout exceeded! Looking for: " + locator.toString()); this.log.warn(ee.toString()); } else { this.log.warn("Execution Exception"); this.log.warn(ee.toString()); } } catch (java.util.concurrent.TimeoutException cte) { this.log.warn("Thread timeout exceeded! Looking for: " + locator.toString()); this.log.warn(cte.toString()); } catch (Exception e) { this.log.error("Exception"); this.log.catching(e); } if (executor != null) { executor.shutdown(); } driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); } catch (Exception ge) { this.log.error("Exception"); this.log.catching(ge); } this.log.debug("WaitForElementInvisibility::Exit"); return isElemVisible; }
From source file:com.pentaho.ctools.utils.ElementHelper.java
License:Apache License
/** * This method pretends to check if the element is present, if it doesn't * we wait for presence for a specific timeout (input), after this, we will * wait for element visible. And, if the element is present then we have to * check if is visible if not wait for visibility. * * @param driver//from w ww . java 2s . co m * @param locator * @param timeout */ public WebElement WaitForElementPresenceAndVisible(final WebDriver driver, final By locator, final Integer timeout) { this.log.debug("WaitForElementPresenceAndVisible::Enter"); this.log.debug("Locator: " + locator.toString()); WebElement element = null; ExecutorService executor = null; driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); try { class RunnableObject implements Runnable { private WebElement theElement; public RunnableObject(WebElement theElement) { this.theElement = theElement; } public WebElement getValue() { return this.theElement; } @Override public void run() { Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(timeout, TimeUnit.SECONDS) .pollingEvery(50, TimeUnit.MILLISECONDS); // Wait for element visible this.theElement = wait.until(new Function<WebDriver, WebElement>() { @Override public WebElement apply(WebDriver d) { try { List<WebElement> listElem = d.findElements(locator); if (listElem.size() > 0) { WebElement elem = listElem.get(0); if (elem != null && ((elem.isEnabled() == true) && (elem.isDisplayed() == true))) { return elem; } return null; } return null; } catch (StaleElementReferenceException sere) { return null; } } }); } } RunnableObject r = new RunnableObject(element); executor = Executors.newSingleThreadExecutor(); executor.submit(r).get(timeout + 2, TimeUnit.SECONDS); element = r.getValue(); } catch (InterruptedException ie) { this.log.warn("Interrupted Exception"); this.log.warn(ie.toString()); } catch (ExecutionException ee) { if (ee.getCause().getClass().getCanonicalName() .equalsIgnoreCase(TimeoutException.class.getCanonicalName())) { this.log.warn("WebDriver timeout exceeded! Looking for: " + locator.toString()); } else { this.log.warn("Execution Exception"); this.log.warn(ee.toString()); } } catch (java.util.concurrent.TimeoutException cte) { this.log.warn("Thread timeout exceeded! Looking for: " + locator.toString()); this.log.warn(cte.toString()); } catch (Exception e) { this.log.error("Exception"); this.log.catching(e); } if (executor != null) { executor.shutdown(); } driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); this.log.debug("WaitForElementPresenceAndVisible::Exit"); return element; }