Example usage for org.openqa.selenium.support.pagefactory ElementLocator findElement

List of usage examples for org.openqa.selenium.support.pagefactory ElementLocator findElement

Introduction

In this page you can find the example usage for org.openqa.selenium.support.pagefactory ElementLocator findElement.

Prototype

WebElement findElement();

Source Link

Usage

From source file:com.cognifide.qa.bb.mapper.field.PageObjectSelectorListProxyProvider.java

License:Apache License

private SearchContext acquireSearchContext(ElementLocatorFactory elementLocatorFactory) {
    SearchContext searchContext;/*from   w  w w  . j  a  v a 2  s .com*/
    ElementLocator parentElementLocator = ((ParentElementLocatorProvider) elementLocatorFactory)
            .getCurrentScope();
    if (parentElementLocator instanceof SearchContextAwareLocator) {
        searchContext = ((SearchContextAwareLocator) parentElementLocator).getSearchContext();
    } else {
        searchContext = parentElementLocator.findElement();
    }
    return searchContext;
}

From source file:org.richfaces.tests.metamer.ftest.checker.IconsCheckerWebdriver.java

License:Open Source License

/**
 * Checks whether icons controlled by CSS work properly (only icons which produce an image)
 *
 * @param attribute icon attribute//from   w  ww .  j  ava  2 s.co m
 * @param icon
 * @param classSuffix
 */
public void checkCssImageIcons(A attribute, ElementLocator icon, String classSuffix) {
    String imageNameSuffix = "";
    if (classSuffix.contains("dis")) {
        imageNameSuffix = "Disabled";
    }
    // option -> css class
    Map<String, String> cssImageIcons = new HashMap<String, String>();
    cssImageIcons.put("chevron", "chevron");
    cssImageIcons.put("chevronDown", "chevron-down");
    cssImageIcons.put("chevronUp", "chevron-up");
    cssImageIcons.put("disc", "disc");
    cssImageIcons.put("grid", "grid");
    cssImageIcons.put("triangle", "triangle");
    cssImageIcons.put("triangleDown", "triangle-down");
    cssImageIcons.put("triangleUp", "triangle-up");
    for (String cssIcon : cssImageIcons.keySet()) {
        if (!setAttributeSilently(attribute, cssIcon)) {
            continue;
        }
        assertTrue(
                icon.findElement().getAttribute("class")
                        .contains(iconPrefix + cssImageIcons.get(cssIcon) + iconSuffix + classSuffix),
                "Div should have set class " + iconPrefix + cssImageIcons.get(cssIcon) + iconSuffix
                        + classSuffix + ".");
        assertTrue(icon.findElement().getCssValue(CssProperty.BACKGROUND_IMAGE.getPropertyName())
                .contains(cssIcon + imageNameSuffix), "Icon should contain a " + cssIcon + ".");
    }
}

From source file:org.richfaces.tests.metamer.ftest.checker.IconsCheckerWebdriver.java

License:Open Source License

/**
 * Checks whether icons controlled by CSS work properly (only icons which don't produce any image)
 *
 * @param attribute icon attribute//  w w  w  . j  a  va2s .c  o  m
 * @param icon
 * @param classSuffix
 */
public void checkCssNoImageIcons(A attribute, ElementLocator icon, String classSuffix) {
    String[] cssNoImageIcons = new String[] { "transparent" };
    for (String cssIcon : cssNoImageIcons) {
        if (!setAttributeSilently(attribute, cssIcon)) {
            continue;
        }
        assertTrue(
                icon.findElement().getAttribute("class")
                        .contains(iconPrefix + cssIcon + iconSuffix + classSuffix),
                "Div should have set class " + iconPrefix + cssIcon + iconSuffix + classSuffix + ".");
        assertTrue(
                icon.findElement().getCssValue(CssProperty.BACKGROUND_IMAGE.getPropertyName()).equals("none"),
                "Icon should not contain any image.");
    }
}

From source file:org.richfaces.tests.metamer.ftest.checker.IconsCheckerWebdriver.java

License:Open Source License

/**
 * Checks whether icon with custom URL works properly
 *
 * @param attribute icon attribute/*w w w.j a va 2 s.  c o m*/
 * @param icon
 * @param image
 * @param classSuffix
 * @param disableIcon set to TRUE if the presence of image element causes that icon element shouldn't be present
 */
public void checkImageIcons(A attribute, ElementLocator icon, By image, String classSuffix,
        boolean disableIcon) {
    // option -> image
    Map<String, String> imageIcons = new HashMap<String, String>();
    imageIcons.put("nonexisting", "nonexisting");
    imageIcons.put("star", "star.png");
    for (String imageIcon : imageIcons.keySet()) {
        if (!setAttributeSilently(attribute, imageIcon)) {
            continue;
        }
        if (disableIcon) {
            assertFalse(Graphene.element(icon.findElement()).isPresent().apply(driver),
                    "Icon's div (" + icon + ") should not be present when icon=" + imageIcon + ".");
        }
        assertTrue(Graphene.element(image).isPresent().apply(driver),
                "Icon's image should be rendered (" + image + ") when icon=" + imageIcon + ".");
        assertTrue(driver.findElement(image).getAttribute("src").contains(imageIcons.get(imageIcon)),
                "Icon's src attribute (" + image + ") should contain " + imageIcons.get(imageIcon)
                        + " when icon=" + imageIcon + ".");
    }
}

From source file:org.richfaces.tests.metamer.ftest.checker.IconsCheckerWebdriver.java

License:Open Source License

/**
 * Checks "icon" contains image element.
 * In the contrary of checkImageIcons this method consider By image as direct child element
 * of icon WebElement, and then By expression for image should not be unique within whole DOM,
 * but just within parent icon element/*from  w  w  w  . j a va  2  s . co m*/
 *
 * It is useful when using page fragments where icon element is reliable and unique localized,
 * but img child element doesn't contains any additional attributes for unique identification.
 * Which is no longer needed since parent element is reliable identified.
 *
 * Used e.g. for PanelMenuGroup icons, where more groups present within menu,
 * but icon images are difficult to localize unique over whole page.
 *
 * @param attribute icon attribute
 * @param icon - root of icon "element" - it is sometime td or something like this, containing additional elements
 * @param image - By location, it should be relative to icon element
 * @param classSuffix
 * @param disableIcon set to TRUE if the presence of image element causes that icon element shouldn't be present
 */
public void checkImageIconsAsRelative(A attribute, ElementLocator icon, By image, String classSuffix,
        boolean disableIcon) {
    // option -> image
    Map<String, String> imageIcons = new HashMap<String, String>();
    imageIcons.put("nonexisting", "nonexisting");
    imageIcons.put("star", "star.png");
    for (String imageIcon : imageIcons.keySet()) {
        if (!setAttributeSilently(attribute, imageIcon)) {
            continue;
        }
        if (disableIcon) {
            assertFalse(Graphene.element(icon.findElement()).isPresent().apply(driver),
                    "Icon's div (" + icon + ") should not be present when icon=" + imageIcon + ".");
        }
        // there is the point: image location referenced By image is relative to icon element
        WebElement imageElem = icon.findElement().findElement(image);
        assertTrue(Graphene.element(imageElem).isPresent().apply(driver),
                "Icon's image should be rendered (" + image + ") when icon=" + imageIcon + ".");
        assertTrue(imageElem.getAttribute("src").contains(imageIcons.get(imageIcon)), "Icon's src attribute ("
                + image + ") should contain " + imageIcons.get(imageIcon) + " when icon=" + imageIcon + ".");
    }
}

From source file:org.richfaces.tests.metamer.ftest.checker.IconsCheckerWebdriver.java

License:Open Source License

public void checkNone(A attribute, ElementLocator icon, String classSuffix) {
    if (!setAttributeSilently(attribute, "none")) {
        return;//w  ww  .  java  2 s  .com
    }
    assertFalse(Graphene.element(icon.findElement()).isPresent().apply(driver),
            "Icon should not be present when icon=none.");
}