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

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

Introduction

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

Prototype

public static ExpectedCondition<Boolean> not(final ExpectedCondition<?> condition) 

Source Link

Document

An expectation with the logical opposite condition of the given condition.

Usage

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

License:Open Source License

private void runFaces_3274InputDateTimeTest(BrowserDriver browserDriver, WaitingAsserter waitingAsserter,
        String inputType, String inputIdSuffix) {

    navigateToUseCase(browserDriver, inputType, "general");

    String showOnButtonInputXpath = getInputDateTimeXpath("button", inputIdSuffix);
    WebElement showOnButtonInput = browserDriver.findElementByXpath(showOnButtonInputXpath);
    waitingAsserter.assertTrue(ExpectedConditions
            .not(ExpectedConditions.attributeToBeNotEmpty(showOnButtonInput, "autocomplete")));

    String showOnFocusInputXpath = getInputDateTimeXpath("focus", inputIdSuffix);
    assertAutocompleteAttributeOff(waitingAsserter, showOnFocusInputXpath);

    String showOnBothInputXpath = getInputDateTimeXpath("both", inputIdSuffix);
    assertAutocompleteAttributeOff(waitingAsserter, showOnBothInputXpath);

    if ("firefox".equals(browserDriver.getBrowserName())) {

        runFACES_3274Test(browserDriver, waitingAsserter, showOnButtonInputXpath, true);

        if ("inputDate".equalsIgnoreCase(inputType)) {

            runFACES_3274Test(browserDriver, waitingAsserter, showOnFocusInputXpath, false);
            runFACES_3274Test(browserDriver, waitingAsserter, showOnBothInputXpath, false);
        }/* w w  w  .  j  a va  2s.c om*/
    }
}

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

License:Open Source License

@Test
@RunAsClient// w  w w.j a v  a  2s.  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);
    }

}

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

License:Open Source License

@Test
@RunAsClient//from  ww  w.  j av a  2 s  .co  m
@InSequence(8000)
public void dateValidation() throws Exception {

    String foo = "";

    // checks an invalid dateOfBirth
    try {
        dateOfBirthField.clear();
        logger.log(Level.INFO, "No exceptions occured when clearing the dateOfBirthField");
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        assertTrue(
                "No exceptions should occur when clearing the dateOfBirthField, but one did occur with the following message: "
                        + e.getMessage(),
                false);
    }

    logger.log(Level.INFO, "Waiting for the dateOfBirthField to contain '' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(dateOfBirthFieldXpath), ""));
        logger.log(Level.INFO, "after clearing dateOfBirthField.getAttribute('value') = "
                + dateOfBirthField.getAttribute("value"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, dateOfBirthFieldErrorXpath)) {
            foo = dateOfBirthFieldError.getText();
        }
        assertTrue("dateOfBirthField should be empty after clearing," + " but " + dateOfBirthFieldXpath
                + " contains '" + foo + "'.", false);
    }

    logger.log(Level.INFO, "Entering an invalid value for the date of birth ... 12/34/5678 ...");
    dateOfBirthField.sendKeys("12/34/5678");

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

    submitButton.click();

    logger.log(Level.INFO, "Waiting for the dateOfBirthFieldError to contain 'Invalid date format' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(dateOfBirthFieldErrorXpath),
                "Invalid date format"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        assertTrue("dateOfBirthFieldError should be visible after submitting with '12/34/5678'," + " but "
                + dateOfBirthFieldErrorXpath + " is not visible.", false);
    }

    logger.log(Level.INFO,
            "dateOfBirthField.getAttribute('value') = " + dateOfBirthField.getAttribute("value"));
    logger.log(Level.INFO, "dateOfBirthFieldError.isDisplayed() = " + dateOfBirthFieldError.isDisplayed());
    logger.log(Level.INFO, "dateOfBirthFieldError.getText() = " + dateOfBirthFieldError.getText());
    assertTrue(
            "dateOfBirthFieldError should contain 'Invalid date format', but insteead contains '"
                    + dateOfBirthFieldError.getText() + "'",
            dateOfBirthFieldError.getText().contains("Invalid date format"));

    // checks with no dateOfBirth
    dateOfBirthField.clear();

    logger.log(Level.INFO, "Waiting for the dateOfBirthField to contain '' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(dateOfBirthFieldXpath), ""));
        logger.log(Level.INFO, "after clearing dateOfBirthField.getAttribute('value') = "
                + dateOfBirthField.getAttribute("value"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, dateOfBirthFieldErrorXpath)) {
            foo = dateOfBirthFieldError.getText();
        }
        assertTrue("dateOfBirthField should be empty after clearing," + " but " + dateOfBirthFieldXpath
                + " contains '" + foo + "'.", false);
    }

    phoneNumberField.click();

    logger.log(Level.INFO, "Waiting for the dateOfBirthFieldError to contain 'Value is required' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(dateOfBirthFieldErrorXpath),
                "Value is required"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        assertTrue(
                "dateOfBirthFieldError should be visible after entering '12/34/5678' and clicking into another field,"
                        + " but " + dateOfBirthFieldErrorXpath + " does not contain 'Value is required'.",
                false);
    }

    logger.log(Level.INFO,
            "dateOfBirthField.getAttribute('value') = " + dateOfBirthField.getAttribute("value"));
    logger.log(Level.INFO, "dateOfBirthFieldError.isDisplayed() = " + dateOfBirthFieldError.isDisplayed());
    logger.log(Level.INFO, "dateOfBirthFieldError.getText() = " + dateOfBirthFieldError.getText());

    // checks a valid dateOfBirth
    foo = "";
    dateOfBirthField.clear();

    logger.log(Level.INFO, "Waiting for the dateOfBirthField to contain '' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(dateOfBirthFieldXpath), ""));
        logger.log(Level.INFO, "after clearing dateOfBirthField.getAttribute('value') = "
                + dateOfBirthField.getAttribute("value"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, dateOfBirthFieldErrorXpath)) {
            foo = dateOfBirthFieldError.getText();
        }
        assertTrue("dateOfBirthField should be empty after clearing," + " but " + dateOfBirthFieldXpath
                + " contains '" + foo + "'.", false);
    }

    logger.log(Level.INFO, "Entering a valid dateOfBirth = 01/02/3456 ...");
    dateOfBirthField.sendKeys("01/02/3456");
    logger.log(Level.INFO, "Clicking into the phoneNumberField ...");
    phoneNumberField.click();

    logger.log(Level.INFO, "Waiting for the dateOfBirthFieldError to disappear ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions
                .not(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(dateOfBirthFieldErrorXpath))));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, dateOfBirthFieldErrorXpath)) {
            foo = dateOfBirthFieldError.getText();
        }
        assertTrue("dateOfBirthFieldError should NOT be visible after entering 01/02/3456," + " but "
                + dateOfBirthFieldErrorXpath + " is still there showing '" + foo + "'", false);
    }

}

From source file:com.liferay.faces.test.selenium.browser.internal.WaitingAsserterImpl.java

License:Open Source License

@Override
public void assertFalse(ExpectedCondition expectedCondition) {

    try {//from ww  w .jav  a  2 s  .  com
        browserDriver.waitFor(ExpectedConditions.not(expectedCondition));
    } catch (TimeoutException e) {
        throw createAssertionErrorWithoutExtraInfo(e);
    }
}

From source file:com.liferay.faces.test.selenium.browser.internal.WaitingAsserterImpl.java

License:Open Source License

@Override
public void assertTextNotPresentInElement(String text, String elementXpath, boolean elementMustBeDisplayed) {

    By byXpath = By.xpath(elementXpath);
    ExpectedCondition<?> expectedCondition = ExpectedConditions
            .not(ExpectedConditions.textToBePresentInElementLocated(byXpath, text));
    expectedCondition = ExpectedConditionsUtil.ifNecessaryExpectElementDisplayed(expectedCondition,
            elementMustBeDisplayed, byXpath);
    assertTrue(expectedCondition);//w w w  .  ja  va  2s. com
}

From source file:com.vaadin.demo.testutil.AbstractDemoTest.java

License:Apache License

/**
 * Waits the given number of seconds for the given condition to become
 * false. Use e.g. as {@link #waitUntilNot(ExpectedCondition)}.
 *
 * @param condition/* w w w  .  j a  v  a 2 s . c o m*/
 *            the condition to wait for to become false
 * @param timeoutInSeconds
 *            the number of seconds to wait
 * @param <T>
 *            the return type of the expected condition
 */
protected <T> void waitUntilNot(ExpectedCondition<T> condition, long timeoutInSeconds) {
    waitUntil(ExpectedConditions.not(condition), timeoutInSeconds);
}

From source file:com.vaadin.testbench.elements.NotificationElement.java

License:Apache License

/**
 * Closes a notification.//from www .j  a v a2  s . c o m
 *
 * @throws TimeoutException
 *             If a notification can not be closed and the timeout expires.
 */
public void close() {
    click();
    WebDriverWait wait = new WebDriverWait(getDriver(), 10);
    wait.until(ExpectedConditions
            .not(ExpectedConditions.presenceOfAllElementsLocatedBy(By.className("v-Notification"))));

}

From source file:com.xwikisas.xcs.test.po.tour.XCSPageWithTour.java

License:Open Source License

@Override
public void previousStep() {
    // Get the current step id
    String stepId = getStepId();//from  www .j  a v a  2  s  . co  m
    // Click
    getDriver().findElement(By.xpath("//button[@data-role='prev']")).click();
    // Wait until current state disappears
    getDriver().waitUntilCondition(
            ExpectedConditions.not(ExpectedConditions.presenceOfAllElementsLocatedBy(By.id(stepId))));
    // Wait until new step appears
    getDriver().waitUntilCondition(ExpectedConditions.presenceOfElementLocated(By.className("tour")));
}

From source file:com.xwikisas.xcs.test.po.tour.XCSPageWithTour.java

License:Open Source License

@Override
public void nextStep() {
    // Get the current step id
    String stepId = getStepId();//from  ww w  . jav a2s  .  co m
    // Click
    getDriver().findElement(By.xpath("//button[@data-role='next']")).click();
    // Wait until current state disappears
    getDriver().waitUntilCondition(
            ExpectedConditions.not(ExpectedConditions.presenceOfAllElementsLocatedBy(By.id(stepId))));
    // Wait until new step appear
    getDriver().waitUntilCondition(ExpectedConditions.presenceOfElementLocated(By.className("tour")));
}

From source file:com.xwikisas.xcs.test.po.tour.XCSPageWithTour.java

License:Open Source License

@Override
public void end() {
    getDriver().findElement(By.xpath("//div[contains(@class, 'popover-navigation')]//button[@data-role='end']"))
            .click();//from ww  w  . j a  v a  2s  .  co  m
    getDriver().waitUntilCondition(
            ExpectedConditions.not(ExpectedConditions.presenceOfAllElementsLocatedBy(By.className("tour"))));
}