Example usage for org.openqa.selenium.support.ui ExpectedConditions textToBePresentInElementValue

List of usage examples for org.openqa.selenium.support.ui ExpectedConditions textToBePresentInElementValue

Introduction

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

Prototype

public static ExpectedCondition<Boolean> textToBePresentInElementValue(final By locator, final String text) 

Source Link

Document

An expectation for checking if the given text is present in the specified elements value attribute.

Usage

From source file:LoginWHTest.java

@Test
public void testAuthenticationFailureWhenProvidingBadCredentials() {
    WebDriverWait wait;//  www .j  a v  a2  s .  c  om
    WebElement username;

    // Click on 'Login' button
    driver2.findElement(
            By.xpath("html/body/div[2]/div/div/div[2]/wf-header/header/div/div[2]/wf-user-button/div/a/span"))
            .click();

    // Enter UserName
    driver2.findElement(By.xpath("//*[@id='loginForm']/div[1]/input")).click();
    driver2.findElement(By.xpath("//*[@id='loginForm']/div[1]/input")).sendKeys("");
    driver2.findElement(By.xpath("//*[@id='loginForm']/div[1]/input")).sendKeys("simeonbin");

    wait = new WebDriverWait(driver2, 60);
    wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath("//*[@id='loginForm']/div[1]/input"),
            "simeonbin"));

    // Enter Password
    driver2.findElement(By.xpath("//*[@id='loginForm']/div[4]/input")).sendKeys("");
    driver2.findElement(By.xpath("//*[@id='loginForm']/div[4]/input")).sendKeys("password");
    wait = new WebDriverWait(driver2, 60);
    wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath("//*[@id='loginForm']/div[4]/input"),
            "password"));

    // Click on 'Login' button
    WebElement login = driver2.findElement(By.xpath("//*[@id='loginForm']/button"));
    wait = new WebDriverWait(driver2, 15);
    login.click();
    wait = new WebDriverWait(driver2, 15);

    String errorMsg = driver2.findElement(By.xpath(" //*[@id='loginForm']/div[7]")).getText();
    System.out.println(errorMsg);

    assertTrue(errorMsg.startsWith("Sorry"));

    driver2.close();
}

From source file:ca.nrc.cadc.web.selenium.AbstractTestWebPage.java

License:Open Source License

protected void waitForFormInputTextPresent(final WebElement webElement, final String text) throws Exception {
    waitUntil(ExpectedConditions.textToBePresentInElementValue(webElement, text));
}

From source file:com.androidwhy.modules.test.selenium.Selenium2.java

License:Apache License

/**
 * Elementvaluevalue, timeout??.// w  w w  .j a v a 2 s  .  com
 */
public void waitForValuePresent(By by, String value, int timeout) {
    waitForCondition(ExpectedConditions.textToBePresentInElementValue(by, value), timeout);
}

From source file:com.asiainfo.tfsPlatform.modules.test.selenium.Selenium2.java

License:Apache License

/**
 * Elementvaluevalue, timeout./*from   www  .j av  a  2 s .  com*/
 */
public void waitForValuePresent(By by, String value) {
    waitForCondition(ExpectedConditions.textToBePresentInElementValue(by, value), DEFAULT_WAIT_TIME);
}

From source file:com.atanas.kanchev.testframework.selenium.handlers.Wait.java

License:Apache License

/**
 * {@inheritDoc}/*  w  w w.  j av  a 2 s.co  m*/
 */
@Override
public boolean isTextPresentInElementValue(By locator, String text, long wait) {
    try {
        getWait(wait).until(ExpectedConditions.textToBePresentInElementValue(locator, text));
        return true;
    } catch (TimeoutException e) {
        logger.error("Timeout after waiting text  " + text + " to be present in element located by "
                + locator.toString());
        throw new TimeoutException(e.getMessage());
    }
}

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 ava 2s. com
 */
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.hotwire.selenium.bex.BexAbstractPage.java

License:Open Source License

protected void waitElementText(String css, String value) {
    new WebDriverWait(getWebDriver(), DEFAULT_WAIT)
            .until(ExpectedConditions.textToBePresentInElementValue(By.cssSelector(css), value));
}

From source file:com.liferay.faces.test.alloy.issue.FACES_3274Tester.java

License:Open Source License

/**
 * This method only works in Firefox./*  w  ww. ja  v  a  2s .  c om*/
 */
private static void runFACES_3274Test(BrowserDriver browserDriver, WaitingAsserter waitingAsserter,
        String inputXpath, boolean isAutocompleteOn) {

    String helloWorld = "Hello World!";
    Actions actions = browserDriver.createActions(inputXpath);
    WebElement inputElement = browserDriver.findElementByXpath(inputXpath);
    actions.sendKeys(inputElement, helloWorld, Keys.ENTER);
    browserDriver.performAndWaitForRerender(actions.build(), inputXpath);
    browserDriver.clearElement(inputXpath);

    String hello = "Hello";
    browserDriver.sendKeysToElement(inputXpath, hello);
    waitingAsserter.assertTextPresentInElementValue(hello, inputXpath);
    browserDriver.sendKeysToElement(inputXpath, Keys.DOWN, Keys.ENTER);
    waitingAsserter.assertTextPresentInElementValue(hello, inputXpath);

    ExpectedCondition<Boolean> textToBePresentInElementValue = ExpectedConditions
            .textToBePresentInElementValue(By.xpath(inputXpath), helloWorld);

    if (isAutocompleteOn) {
        waitingAsserter.assertTrue(textToBePresentInElementValue);
    } else {
        waitingAsserter.assertFalse(textToBePresentInElementValue);
    }
}

From source file:com.liferay.faces.test.AlloyApplicantPortletTest.java

License:Open Source License

@Test
@RunAsClient/*from  w  ww . ja  va2s  .c o  m*/
@InSequence(1500)
public void dataEntry() throws Exception {

    String foo = "";

    logger.log(Level.INFO, "clicking into the firstNameField ...");
    firstNameField.click();
    logger.log(Level.INFO, "tabbing into the next field ...");
    firstNameField.sendKeys(Keys.TAB);

    logger.log(Level.INFO, "firstNameField.getAttribute('value') = " + firstNameField.getAttribute("value"));
    logger.log(Level.INFO,
            "isThere(browser, firstNameFieldErrorXpath) = " + isThere(browser, firstNameFieldErrorXpath));

    if (isThere(browser, firstNameFieldErrorXpath)) { // houston we have a problem
        logger.log(Level.INFO, "firstNameFieldError.isDisplayed() = " + firstNameFieldError.isDisplayed());
        assertFalse(
                "firstNameFieldError should not be displayed after simply tabbing out of the empty field, having never entered any data.  "
                        + "But we see '" + firstNameFieldError.getText() + "'",
                firstNameFieldError.isDisplayed());
    }

    logger.log(Level.INFO, "Shift tabbing back into the firstNameField ...");
    (new Actions(browser)).keyDown(Keys.SHIFT).sendKeys(Keys.TAB).keyDown(Keys.SHIFT).perform();

    logger.log(Level.INFO,
            "isThere(browser, firstNameFieldErrorXpath) = " + isThere(browser, firstNameFieldErrorXpath));

    logger.log(Level.INFO, "entering 'asdf' into the firstNameField and then tabbing out of it...");
    firstNameField.sendKeys("asdf");
    firstNameField.sendKeys(Keys.TAB);

    logger.log(Level.INFO, "firstNameField.getAttribute('value') = " + firstNameField.getAttribute("value"));
    logger.log(Level.INFO,
            "isThere(browser, firstNameFieldErrorXpath) = " + isThere(browser, firstNameFieldErrorXpath));
    assertTrue("The data 'asdf' should be in the firstNameField after tabbing out of it",
            "asdf".equals(firstNameField.getAttribute("value")));

    logger.log(Level.INFO, "Shift tabbing back into the firstNameField ...");
    (new Actions(browser)).keyDown(Keys.SHIFT).sendKeys(Keys.TAB).keyUp(Keys.SHIFT).perform();

    firstNameField.click();
    logger.log(Level.INFO,
            "clearing the firstNameField using the BACKSPACE key, and then tabbing out of the firstNameField ...");
    firstNameField.sendKeys(Keys.ARROW_RIGHT, Keys.BACK_SPACE);

    logger.log(Level.INFO, "Waiting for the firstNameField to contain 'asd' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(firstNameFieldXpath), "asd"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, firstNameFieldXpath)) {
            foo = firstNameField.getText();
        }
        logger.log(Level.INFO, "firstNameField.getText() = " + firstNameField.getText());
        assertTrue(
                "firstNameField should contain 'asd', but " + firstNameFieldXpath + " contains '" + foo + "'.",
                false);
    }

    firstNameField.sendKeys(Keys.BACK_SPACE);

    logger.log(Level.INFO, "Waiting for the firstNameField to contain 'as' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(firstNameFieldXpath), "as"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, firstNameFieldXpath)) {
            foo = firstNameField.getText();
        }
        assertTrue(
                "firstNameField should contain 'as', but " + firstNameFieldXpath + " contains '" + foo + "'.",
                false);
    }

    firstNameField.sendKeys(Keys.BACK_SPACE);

    logger.log(Level.INFO, "Waiting for the firstNameField to contain 'a' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(firstNameFieldXpath), "a"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, firstNameFieldXpath)) {
            foo = firstNameField.getText();
        }
        assertTrue("firstNameField should contain 'a', but " + firstNameFieldXpath + " contains '" + foo + "'.",
                false);
    }

    firstNameField.sendKeys(Keys.BACK_SPACE);

    logger.log(Level.INFO, "Waiting for the firstNameField to contain '' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(firstNameFieldXpath), ""));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, firstNameFieldXpath)) {
            foo = firstNameField.getText();
        }
        assertTrue("firstNameField should contain '', but " + firstNameFieldXpath + " contains '" + foo + "'.",
                false);
    }

    firstNameField.sendKeys(Keys.TAB);

    logger.log(Level.INFO, "Waiting for the firstNameFieldError to contain 'Value is required' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(firstNameFieldErrorXpath),
                "Value is required"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        assertTrue("firstNameFieldError should be visible after tabbing out with no value," + " but "
                + firstNameFieldErrorXpath + " is not visible.", false);
    }

    logger.log(Level.INFO, "firstNameField.getAttribute('value') = " + firstNameField.getAttribute("value"));
    assertTrue(
            "The data 'asdf' should no longer be in the firstNameField after clearing it out with BACK_SPACE and then tabbing out.   "
                    + "But we see '" + firstNameField.getAttribute("value") + "'",
            "".equals(firstNameField.getAttribute("value")));
    logger.log(Level.INFO,
            "isThere(browser, firstNameFieldErrorXpath) = " + isThere(browser, firstNameFieldErrorXpath));
    assertTrue(
            "The firstNameFieldError should at least be in the DOM somewhere by this point, but it is not there",
            isThere(browser, firstNameFieldErrorXpath));
    logger.log(Level.INFO, "firstNameFieldError.getText() = " + firstNameFieldError.getText());
    assertTrue("The firstNameFieldError should say 'Value is required'",
            firstNameFieldError.getText().contains("Value is required"));

}

From source file:com.liferay.faces.test.AlloyApplicantPortletTest.java

License:Open Source License

@Test
@RunAsClient//w  w w  . j a  va2  s  .  c o  m
@InSequence(2000)
public void validateEmail() throws Exception {

    String foo = "";

    // checks an invalid email address
    logger.log(Level.INFO, "Entering an invalid email address 'test' ...");
    emailAddressField.sendKeys("test");
    phoneNumberField.click();

    logger.log(Level.INFO, "Waiting for the emailAddressFieldError to contain 'Invalid e-mail address' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(emailAddressFieldErrorXpath),
                "Invalid e-mail address"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        assertTrue("emailAddressField should be visible after tabbing out with no value," + " but "
                + emailAddressFieldErrorXpath + " is not visible.", false);
    }
    logger.log(Level.INFO,
            "emailAddressField.getAttribute('value') = " + emailAddressField.getAttribute("value"));

    assertTrue("Invalid e-mail address validation message displayed",
            emailAddressFieldError.getText().contains("Invalid e-mail address"));
    logger.log(Level.INFO, "emailAddressFieldError.isDisplayed() = " + emailAddressFieldError.isDisplayed());
    logger.log(Level.INFO, "emailAddressFieldError.getText() = " + emailAddressFieldError.getText());

    // checks a valid email address
    logger.log(Level.INFO, "Waiting for the emailAddressFieldError to contain '' ...");
    try {
        emailAddressField.clear();
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(emailAddressFieldXpath), ""));
        logger.log(Level.INFO, "emailAddressField.getText() = '" + emailAddressField.getText() + "'");
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, emailAddressFieldXpath)) {
            foo = emailAddressField.getText();
        }
        assertTrue("emailAddressField should be clear," + " but " + emailAddressFieldXpath + " contains '" + foo
                + "'", false);
    }

    logger.log(Level.INFO, "Entering a valid email address 'test@liferay.com' ...");
    emailAddressField.click();
    emailAddressField.sendKeys("test@liferay.com");
    emailAddressField.sendKeys(Keys.TAB);
    phoneNumberField.click();

    logger.log(Level.INFO, "Waiting for the emailAddressField to contain 'test@liferay.com' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(emailAddressFieldXpath),
                "test@liferay.com"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, emailAddressFieldXpath)) {
            foo = emailAddressField.getText();
        }
        assertTrue("emailAddressField should contain 'test@liferay.com'," + " but " + emailAddressFieldXpath
                + " contains '" + foo + "'", false);
    }

    logger.log(Level.INFO, "Waiting for the emailAddressFieldError to disappear ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions
                .not(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(emailAddressFieldErrorXpath))));
        logger.log(Level.INFO,
                "emailAddressField.getAttribute('value') = " + emailAddressField.getAttribute("value"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, emailAddressFieldErrorXpath)) {
            foo = emailAddressFieldError.getText();
        }
        assertTrue("emailAddressFieldError should NOT be visible after entering 'test@liferay.com'," + " but "
                + emailAddressFieldErrorXpath + " is still there showing '" + foo + "'", false);
    }

}