Example usage for org.openqa.selenium.support.ui WebDriverWait WebDriverWait

List of usage examples for org.openqa.selenium.support.ui WebDriverWait WebDriverWait

Introduction

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

Prototype

public WebDriverWait(WebDriver driver, Duration timeout) 

Source Link

Document

Wait will ignore instances of NotFoundException that are encountered (thrown) by default in the 'until' condition, and immediately propagate all others.

Usage

From source file:com.gdf.managedBean.TendererRegistrationBeanTest.java

@Test
public void registration() {
    // Preparation
    driver.get(baseUrl);/*from  w  w w  .j av a2 s. com*/

    inputLogin = driver.findElement(By.xpath("//input[contains(@id,'registerTendererForm:registerLogin')]"));
    inputPassword = driver
            .findElement(By.xpath("//input[contains(@id,'registerTendererForm:registerPassword')]"));
    inputConfirmPassword = driver
            .findElement(By.xpath("//input[contains(@id,'registerTendererForm:registerConfirmPassword')]"));
    inputMail = driver.findElement(By.xpath("//input[contains(@id,'registerTendererForm:registerMail')]"));
    inputFirstname = driver
            .findElement(By.xpath("//input[contains(@id,'registerTendererForm:registerFirstname')]"));
    inputLastName = driver
            .findElement(By.xpath("//input[contains(@id,'registerTendererForm:registerLastname')]"));
    inputPhone = driver
            .findElement(By.xpath("//input[contains(@id,'registerTendererForm:registerPhoneNumber')]"));
    inputAvatar = driver.findElement(By.xpath("//input[contains(@id,'registerTendererForm:registerAvatar')]"));

    registerButton = driver
            .findElement(By.xpath("//button[contains(@id,'registerTendererForm:tenderRegisterButton')]"));

    inputLogin.clear();
    inputLogin.sendKeys("SuperTenderer" + new Random().nextInt(1000));
    inputPassword.clear();
    inputPassword.sendKeys("password1234");
    inputConfirmPassword.clear();
    inputConfirmPassword.sendKeys("password1234");
    inputMail.clear();
    inputMail.sendKeys("super.tenderer@mymail.com");
    inputFirstname.clear();
    inputFirstname.sendKeys("I'm the");
    inputLastName.clear();
    inputLastName.sendKeys("SuperTenderer");
    inputPhone.clear();
    inputPhone.sendKeys("2820092809");
    inputAvatar.clear();
    inputAvatar.sendKeys("http://www.batterytender.com/assets/img/logo_BTmainNav.png");

    registerButton.click();

    // Test
    WebElement growlTitle = (new WebDriverWait(driver, 10))
            .until(ExpectedConditions.presenceOfElementLocated(By.className("ui-growl-title")));

    // Verification
    assertEquals(growlTitle.getText(), "Inscription russie !");
}

From source file:com.ggasoftware.uitest.control.Element.java

License:Open Source License

/**
 * Wait until element exists.// w w w .  j a va2s.c o m
 *
 * @param timeoutSec     seconds to wait until element exists.
 * @param checkCondition log assert for expected conditions.
 * @return Parent instance
 */
public ParentPanel waitForExists(int timeoutSec, boolean checkCondition) {
    boolean isExists;
    logAction(this, getParentClassName(), format("waitForExists: %s", locator));
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    setTimeout(1);
    try {
        wait.until(ExpectedConditions.presenceOfElementLocated(avatar.byLocator));
        isExists = true;
    } catch (TimeoutException e) {
        logTechnical(format("waitForExists: [ %s ] during: [ %d ] sec ", locator,
                System.currentTimeMillis() / 1000 - start));
        isExists = false;
    }
    setTimeout(TIMEOUT);
    if (checkCondition) {
        logAssertTrue(BUSINESS_LEVEL, isExists, format("waitForExists - '%s' should exist", getName()),
                takePassedScreenshot);
    }
    return parent;
}

From source file:com.ggasoftware.uitest.control.Element.java

License:Open Source License

/**
 * Wait until element is displayed./*from w  w  w.ja  v  a 2 s  .  c  o  m*/
 *
 * @param timeoutSec     seconds to wait until element is displayed.
 * @param checkCondition log assert for expected conditions.
 * @return Parent instance
 */
private ParentPanel waitForDisplayed(int timeoutSec, boolean checkCondition) {
    boolean isDisplayed;
    logAction(this, getParentClassName(), format("waitForDisplayed: %s", locator));
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    setTimeout(1);
    try {
        wait.until(ExpectedConditions.visibilityOfElementLocated(avatar.byLocator));
        isDisplayed = true;
    } catch (TimeoutException e) {
        logTechnical(format("waitForDisplayed: [ %s ] during: [ %d ] sec ", locator,
                System.currentTimeMillis() / 1000 - start));
        isDisplayed = false;
    }
    setTimeout(TIMEOUT);
    if (checkCondition) {
        logAssertTrue(BUSINESS_LEVEL, isDisplayed,
                format("waitForDisplayed - '%s' should be displayed", getName()), takePassedScreenshot);
    }
    return parent;
}

From source file:com.ggasoftware.uitest.control.Element.java

License:Open Source License

/**
 * Wait until element is vanished.//w ww . j  av  a2  s.co m
 *
 * @param timeoutSec     -  the maximum time to wait in seconds (until element become invisible or disappeared)
 * @param checkCondition log assert for expected conditions.
 * @return Parent instance
 */
public ParentPanel waitForElementToVanish(int timeoutSec, boolean checkCondition) {
    boolean isVanished;
    logAction(this, getParentClassName(), format("waitForElementToVanish: %s", locator));
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class, NoSuchElementException.class);
    setTimeout(1);
    try {
        isVanished = wait.until(ExpectedConditions.invisibilityOfElementLocated(avatar.byLocator));
    } catch (TimeoutException e) {
        logTechnical(format("waitForElementToVanish: [ %s ] during: [ %d ] sec ", locator,
                System.currentTimeMillis() / 1000 - start));
        isVanished = false;
    }
    setTimeout(TIMEOUT);
    if (checkCondition) {
        logAssertTrue(BUSINESS_LEVEL, isVanished,
                format("waitForElementToVanish - '%s' should be vanished", getName()), takePassedScreenshot);
    }
    return parent;
}

From source file:com.ggasoftware.uitest.control.Element.java

License:Open Source License

/**
 * Wait until element has a text.//  w  w  w .  j a v a  2 s. c o m
 *
 * @param text           Text of Element
 * @param timeoutSec     seconds to wait until element has a text
 * @param checkCondition log assert for expected conditions.
 * @return Parent instance
 */
public ParentPanel waitForText(final String text, final int timeoutSec, final boolean checkCondition) {
    boolean isPresent;
    logAction(this, getParentClassName(), format("waitForText[%s]: %s", text, locator));
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    try {
        wait.until(ExpectedConditions.textToBePresentInElementLocated(avatar.byLocator, text));
        getText();
        isPresent = wait.until(new ExpectedCondition<Boolean>() {
            @Override
            public Boolean apply(WebDriver driver) {
                return getDriver().findElement(avatar.byLocator).getText().equals(text);
            }
        });
    } catch (TimeoutException e) {
        logTechnical(format("waitForText: [ %s ] during: [ %d ] sec ", locator,
                System.currentTimeMillis() / 1000 - start));
        isPresent = false;
    }
    if (checkCondition) {
        logAssertTrue(BUSINESS_LEVEL, isPresent,
                format("waitForText - '%s' should has a text '%s'", getName(), text), takePassedScreenshot);
    }
    return parent;
}

From source file:com.ggasoftware.uitest.control.Element.java

License:Open Source License

/**
 * Wait until element contains a text.//from w ww .  j a v  a2  s  .  co  m
 *
 * @param text           Text of Element
 * @param timeoutSec     seconds to wait until element contains a text
 * @param checkCondition log assert for expected conditions.
 * @return Parent instance
 */
public ParentPanel waitForTextContains(final String text, final int timeoutSec, final boolean checkCondition) {
    boolean isPresent;
    logAction(this, getParentClassName(), format("waitForTextContains[%s]: %s", text, locator));
    long start = System.currentTimeMillis() / 1000;
    final WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    try {
        isPresent = wait.until(ExpectedConditions.textToBePresentInElementLocated(avatar.byLocator, text));
    } catch (TimeoutException e) {
        logTechnical(format("waitForTextContains: [ %s ] during: [ %d ] sec ", locator,
                System.currentTimeMillis() / 1000 - start));
        isPresent = false;
    }
    if (checkCondition) {
        logAssertTrue(BUSINESS_LEVEL, isPresent,
                format("waitForTextContains - '%s' should has a text contains '%s'", getName(), text),
                takePassedScreenshot);
    }
    return parent;
}

From source file:com.ggasoftware.uitest.control.Element.java

License:Open Source License

/**
 * Wait until element is changed text.// w w  w.j av  a  2s . c o m
 *
 * @param text           before change
 * @param timeoutSec     seconds to wait until element is changed text
 * @param checkCondition log assert for expected conditions.
 * @return Parent instance
 */
public ParentPanel waitForTextChanged(final String text, final int timeoutSec, final boolean checkCondition) {
    boolean isChanged;
    logAction(this, getParentClassName(), format("waitForTextChanged[%s]: %s", text, locator));
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    try {
        isChanged = wait.until(ExpectedConditions
                .not(ExpectedConditions.textToBePresentInElementLocated(avatar.byLocator, text)));
    } catch (TimeoutException e) {
        logTechnical(format("waitForTextChanged: [ %s ] during: [ %d ] sec ", locator,
                System.currentTimeMillis() / 1000 - start));
        isChanged = false;
    }
    if (checkCondition) {
        logAssertTrue(BUSINESS_LEVEL, isChanged,
                format("waitForTextChanged - '%s' text '%s' should be changed", getName(), text),
                takePassedScreenshot);
    }
    return parent;
}

From source file:com.ggasoftware.uitest.control.Element.java

License:Open Source License

/**
 * Wait until element has a 'value' attribute.
 *
 * @param value          'Value' Attribute of Element
 * @param timeoutSec     seconds to wait until element has a 'value' attribute
 * @param checkCondition log assert for expected conditions.
 * @return Parent instance/*from  w w  w  .  j  ava2  s.  c  o m*/
 */
public ParentPanel waitForValue(final String value, final int timeoutSec, final boolean checkCondition) {
    boolean isPresent;
    logAction(this, getParentClassName(), format("waitForValueAttribute[%s]: %s", value, locator));
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    try {
        isPresent = wait.until(ExpectedConditions.textToBePresentInElementValue(avatar.byLocator, value));
    } catch (TimeoutException e) {
        logTechnical(format("waitForValueAttribute: [ %s ] during: [ %d ] sec ", locator,
                System.currentTimeMillis() / 1000 - start));
        isPresent = false;
    }
    if (checkCondition) {
        logAssertTrue(BUSINESS_LEVEL, isPresent,
                format("waitForValueAttribute - '%s' should has a value attribute '%s'", getName(), value),
                takePassedScreenshot);
    }
    return parent;
}

From source file:com.ggasoftware.uitest.control.Element.java

License:Open Source License

/**
 * Wait until element is clickable and click at it.
 *
 * @param timeoutSec seconds to wait until element become clickable.
 * @return Parent instance//w  ww . j a va 2s.  c  o m
 */
public ParentPanel waitForClickableAndClick(final int timeoutSec) {
    boolean isClicked;
    logAction(this, getParentClassName(), format("waitForClickable: %s", locator));
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    try {
        wait.until(ExpectedConditions.elementToBeClickable(avatar.byLocator));
        isClicked = wait.until(new ExpectedCondition<Boolean>() {
            @Override
            public Boolean apply(WebDriver driver) {
                try {
                    setTimeout(timeoutSec);
                    getWebElement().click();
                    setTimeout(TIMEOUT);
                    return true;
                } catch (Exception e) {
                    return false;
                }
            }
        });
    } catch (TimeoutException e) {
        logTechnical(format("waitForClickable: [ %s ] during: [ %d ] sec ", locator,
                System.currentTimeMillis() / 1000 - start));
        isClicked = false;
    }
    logAssertTrue(BUSINESS_LEVEL, isClicked,
            format("waitForClickableAndClick: '%s' was clickable and click at it", getName()),
            takePassedScreenshot);
    return parent;
}

From source file:com.ggasoftware.uitest.control.Element.java

License:Open Source License

/**
 * Wait until Expected Condition.//from   ww  w .  ja v a  2  s.c  o m
 *
 * @param condition      - Expected Condition
 * @param timeoutSec     - the maximum time to wait in seconds
 * @param checkCondition log assert for expected conditions.
 * @return Parent instance
 */
public ParentPanel waitForExpectedConditions(final ExpectedCondition<Boolean> condition, final int timeoutSec,
        final boolean checkCondition) {
    boolean isTrue;
    logAction(this, getParentClassName(), format("waitForExpectedCondition[%s}: %s", condition, locator));
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    setTimeout(1);
    try {
        wait.until(condition);
        isTrue = false;
    } catch (TimeoutException e) {
        logTechnical(format("waitForExpectedCondition: [ %s ] during: [ %d ] sec ", locator,
                System.currentTimeMillis() / 1000 - start));
        isTrue = true;
    }
    setTimeout(TIMEOUT);
    if (checkCondition) {
        logAssertFalse(BUSINESS_LEVEL, isTrue, format("waitForExpectedCondition - '%s'", condition),
                takePassedScreenshot);
    }
    return parent;
}