Example usage for org.openqa.selenium.lift.find Finder findFrom

List of usage examples for org.openqa.selenium.lift.find Finder findFrom

Introduction

In this page you can find the example usage for org.openqa.selenium.lift.find Finder findFrom.

Prototype

Collection<S> findFrom(T context);

Source Link

Usage

From source file:org.openmrs.CustomWebDriverContext.java

License:Mozilla Public License

public void assertPresenceOf(Matcher<Integer> cardinalityConstraint, Finder<WebElement, WebDriver> finder) {
    Collection<WebElement> foundElements = finder.findFrom(driver);
    if (!cardinalityConstraint.matches(foundElements.size())) {
        Description description = new StringDescription();
        description.appendText("\nExpected: ").appendDescriptionOf(cardinalityConstraint).appendText(" ")
                .appendDescriptionOf(finder).appendText("\n     got: ").appendValue(foundElements.size())
                .appendText(" ").appendDescriptionOf(finder).appendText("\n");

        failWith(description.toString());
    }//w ww. j  a  v  a  2s  .c  o m
}

From source file:org.openmrs.CustomWebDriverContext.java

License:Mozilla Public License

private WebElement findFirstElementTo(String action, Finder<WebElement, WebDriver> finder) {
    Collection<WebElement> foundElements = finder.findFrom(driver);
    if (foundElements.isEmpty()) {
        failWith("could not find element to " + action);
    }/*  w w  w .j a va2  s  .co m*/

    return foundElements.iterator().next();
}

From source file:org.openmrs.CustomWebDriverContext.java

License:Mozilla Public License

private WebElement findOneElementTo(String action, Finder<WebElement, WebDriver> finder) {
    Collection<WebElement> foundElements = finder.findFrom(driver);
    if (foundElements.isEmpty()) {
        failWith("could not find element to " + action);
    } else if (foundElements.size() > 1) {
        failWith("did not know what to " + action + " - ambiguous");
    }//from w  w  w .  jav  a  2  s.  co m

    return foundElements.iterator().next();
}

From source file:org.openmrs.CustomWebDriverContext.java

License:Mozilla Public License

public void waitFor(Finder<WebElement, WebDriver> finder, long timeoutMillis) {
    long timeoutTime = clock.now() + timeoutMillis;
    while (clock.now() < timeoutTime) {
        Collection<WebElement> result = finder.findFrom(driver);
        for (WebElement webElement : result) {
            if ((webElement).isDisplayed()) {
                return; // found it
            }/* www .  j  a va 2s .  c o m*/
        }
    }
    failWith("Element was not rendered within " + timeoutMillis + "ms");
}

From source file:org.openmrs.steps.LoginPageSteps.java

License:Open Source License

private boolean userAlreadyLoggedIn() {
    Finder<WebElement, WebDriver> f = finderByXpath("//span[@id='userLoggedInAs']")
            .with(text(containsString("Currently logged in")));
    return f.findFrom(getWebDriver()).size() > 0;
}

From source file:org.openmrs.Steps.java

License:Mozilla Public License

/**
 * A finder which returns the first element matched - such as if you have multiple elements
 * which match the finder (such as multiple links with the same text on a page etc)
 *//*from  ww  w  . j a v a 2 s.com*/
public static Finder<WebElement, WebDriver> second(final Finder<WebElement, WebDriver> finder) {
    return new BaseFinder<WebElement, WebDriver>() {

        @Override
        public Collection<WebElement> findFrom(WebDriver context) {
            Collection<WebElement> collection = super.findFrom(context);
            if (collection.size() > 1) {
                Iterator<WebElement> iter = collection.iterator();
                iter.next();
                return Collections.singletonList(iter.next());
            } else {
                return collection;
            }
        }

        protected Collection<WebElement> extractFrom(WebDriver context) {
            return finder.findFrom(context);
        }

        protected void describeTargetTo(Description description) {
            description.appendText("second ");
            finder.describeTo(description);
        }
    };
}