Example usage for org.openqa.selenium.support.ui Wait until

List of usage examples for org.openqa.selenium.support.ui Wait until

Introduction

In this page you can find the example usage for org.openqa.selenium.support.ui Wait until.

Prototype

<T> T until(Function<? super F, T> isTrue);

Source Link

Document

Implementations should wait until the condition evaluates to a value that is neither null nor false.

Usage

From source file:org.jboss.forge.scaffold.angularjs.scenario.dronetests.singleentityvalidations.CustomerViewWithValidationsClient.java

License:Open Source License

@Test
public void testSaveNewCustomerWithInvalidLengths(@ArquillianResource URL baseUrl) throws Exception {
    Wait<WebDriver> wait = new WebDriverWait(driver, 10);

    // Click on the Customers nav entry
    driver.get(baseUrl.toString() + "app.html#/");
    driver.findElement(By.linkText("Customers")).click();
    wait.until(new HasLandedOnSearchCustomerView());

    // Choose to create a new customer 
    driver.findElement(By.id("Create")).click();
    wait.until(new HasLandedOnNewCustomerView());

    // Enter the customer details
    driver.findElement(By.id("firstName")).clear();
    driver.findElement(By.id("firstName")).sendKeys("A");

    assertTrue(isBootstrapErrorDisplayedForFormControl("firstNameControls", "minimum length is 3"));

    driver.findElement(By.id("firstName")).clear();
    String TWO_HUNDRED_As = new String(new char[200]).replaceAll("\0", "A");
    driver.findElement(By.id("firstName")).sendKeys(TWO_HUNDRED_As);

    assertTrue(isBootstrapErrorDisplayedForFormControl("firstNameControls", "maximum length is 100"));
}

From source file:org.jboss.forge.scaffold.angularjs.scenario.dronetests.singleentityvalidations.CustomerViewWithValidationsClient.java

License:Open Source License

@Test
public void testSaveNewCustomerWithInvalidNumbers(@ArquillianResource URL baseUrl) throws Exception {
    Wait<WebDriver> wait = new WebDriverWait(driver, 10);

    // Click on the Customers nav entry
    driver.get(baseUrl.toString() + "app.html#/");
    driver.findElement(By.linkText("Customers")).click();
    wait.until(new HasLandedOnSearchCustomerView());

    // Choose to create a new customer 
    driver.findElement(By.id("Create")).click();
    wait.until(new HasLandedOnNewCustomerView());

    // Enter the customer details
    driver.findElement(By.id("ficoCreditScore")).clear();
    driver.findElement(By.id("ficoCreditScore")).sendKeys("A");
    assertTrue(isBootstrapErrorDisplayedForFormControl("ficoCreditScoreControls", "not a number"));

    // Enter the customer details
    driver.findElement(By.id("ficoCreditScore")).clear();
    driver.findElement(By.id("ficoCreditScore")).sendKeys("200");
    assertTrue(isBootstrapErrorDisplayedForFormControl("ficoCreditScoreControls", "minimum allowed is 300"));

    // Enter the customer details
    driver.findElement(By.id("ficoCreditScore")).clear();
    driver.findElement(By.id("ficoCreditScore")).sendKeys("1000");
    assertTrue(isBootstrapErrorDisplayedForFormControl("ficoCreditScoreControls", "maximum allowed is 850"));
}

From source file:org.jitsi.meet.test.util.MeetUtils.java

License:Apache License

/**
 * Waits for the page to be loaded before continuing with the operations.
 * @param driver the webdriver that just loaded a page
 *///w  w w .  j a  v  a  2  s.  co  m
public static void waitForPageToLoad(WebDriver driver) {
    ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver driver) {
            return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete");
        }
    };
    Wait<WebDriver> wait = new WebDriverWait(driver, 10);
    try {
        wait.until(expectation);
    } catch (Throwable error) {
        assertFalse("Timeout waiting for Page Load Request to complete.", true);
    }
}

From source file:org.nuxeo.ftest.cap.ITSafeEditTest.java

License:Apache License

private void checkSafeEditRestoreProvided() {
    // We must find the status message asking if we want to restore
    // previous unchanged data, and make sure it is visible
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(5, TimeUnit.SECONDS)
            .pollingEvery(100, TimeUnit.MILLISECONDS).ignoring(NoSuchElementException.class);
    wait.until(new Function<WebDriver, WebElement>() {
        @Override/*from w  w w.  j  a  v a  2s . com*/
        public WebElement apply(WebDriver driver) {
            List<WebElement> elts = driver
                    .findElements(By.xpath("//div[contains(.,'A draft of this document has been saved')]"));
            if (!elts.isEmpty()) {
                return elts.get(0);
            }
            return null;
        }
    });
}

From source file:org.nuxeo.ftest.cap.ITSafeEditTest.java

License:Apache License

private void waitForSavedNotification() {
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(5, TimeUnit.SECONDS)
            .pollingEvery(100, TimeUnit.MILLISECONDS).ignoring(NoSuchElementException.class);
    try {//from ww w.  j a va2  s .  c om
        wait.until(new Function<WebDriver, WebElement>() {
            @Override
            public WebElement apply(WebDriver driver) {
                return driver
                        .findElement(By.xpath("//div[contains(.,'" + DRAFT_SAVE_TEXT_NOTIFICATION + "')]"));
            }
        });
    } 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.");
    }
}

From source file:org.nuxeo.functionaltests.AbstractTest.java

License:Open Source License

public static List<WebElement> findElementsWithTimeout(final By by) throws NoSuchElementException {
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(LOAD_TIMEOUT_SECONDS, TimeUnit.SECONDS)
            .pollingEvery(POLLING_FREQUENCY_SECONDS, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);
    return wait.until(new Function<WebDriver, List<WebElement>>() {
        public List<WebElement> apply(WebDriver driver) {
            List<WebElement> elements = driver.findElements(by);
            return elements.isEmpty() ? null : elements;
        }//from  w  ww  . ja  v  a 2s.co m
    });
}

From source file:org.nuxeo.functionaltests.AbstractTest.java

License:Open Source License

/**
 * Fluent wait for an element to be present, checking every 5 seconds
 *
 * @since 5.7.2/*from w w w  .  j  a v a2s . co  m*/
 */
public static WebElement waitUntilElementPresent(final By locator) {
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(LOAD_TIMEOUT_SECONDS, TimeUnit.SECONDS)
            .pollingEvery(POLLING_FREQUENCY_SECONDS, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);
    WebElement elt = wait.until(new Function<WebDriver, WebElement>() {
        public WebElement apply(WebDriver driver) {
            return driver.findElement(locator);
        }
    });
    return elt;
}

From source file:org.nuxeo.functionaltests.AbstractTest.java

License:Open Source License

/**
 * Fluent wait for an element not to be present, checking every 5 seconds.
 *
 * @since 5.7.2/*from   w  w w.jav a 2 s. c  o m*/
 */
public static void waitUntilElementNotPresent(final By locator) {
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(LOAD_TIMEOUT_SECONDS, TimeUnit.SECONDS)
            .pollingEvery(POLLING_FREQUENCY_SECONDS, TimeUnit.SECONDS);
    wait.until((new Function<WebDriver, By>() {
        public By apply(WebDriver driver) {
            try {
                driver.findElement(locator);
            } catch (NoSuchElementException ex) {
                // ok
                return locator;
            }
            return null;
        }
    }));
}

From source file:org.nuxeo.functionaltests.AbstractTest.java

License:Open Source License

/**
 * Fluent wait for text to be present in the element retrieved with the
 * given method./*from  w  w w.  j  av a2 s.  co m*/
 *
 * @since 5.7.3
 */
public static void waitForTextPresent(By locator, String text) {
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(LOAD_TIMEOUT_SECONDS, TimeUnit.SECONDS)
            .pollingEvery(POLLING_FREQUENCY_SECONDS, TimeUnit.SECONDS);
    wait.until(ExpectedConditions.textToBePresentInElement(locator, text));
}

From source file:org.nuxeo.functionaltests.AbstractTest.java

License:Open Source License

/**
 * Fluent wait for text to be present in the given element.
 *
 * @since 5.7.3/*from  w  ww.  j a  v a 2s  .  co m*/
 */
public static void waitForTextPresent(final WebElement element, final String text) {
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(LOAD_TIMEOUT_SECONDS, TimeUnit.SECONDS)
            .pollingEvery(POLLING_FREQUENCY_SECONDS, TimeUnit.SECONDS);
    wait.until((new Function<WebDriver, Boolean>() {
        public Boolean apply(WebDriver driver) {
            try {
                return element.getText().contains(text);
            } catch (StaleElementReferenceException e) {
                return null;
            }
        }
    }));
}