Search in sources :

Example 1 with HtmlFindUtils

use of ru.sbtqa.tag.pagefactory.find.HtmlFindUtils in project page-factory-2 by sbtqa.

the class HtmlStepsImpl method find.

/**
 * Find element with given value in specified list User|he keywords are
 * optional
 *
 * @param listTitle title of the list to search for
 * @param value required value of the element. for text elements value is
 * being checked via getText() method
 * @return Returns itself
 * @throws PageException if page wasn't initialized of required list wasn't
 * found
 */
public T find(String listTitle, String value) throws PageException {
    List<WebElement> elements = ((HtmlFindUtils) Environment.getFindUtils()).findList(null, value);
    WebElement element = ElementUtils.getElementByTextWithEmptyResult(elements, value);
    Assert.assertNotNull(String.format("Element with text '%s' is absent in list '%s'", value, listTitle), element);
    return (T) this;
}
Also used : HtmlFindUtils(ru.sbtqa.tag.pagefactory.find.HtmlFindUtils) WebElement(org.openqa.selenium.WebElement) HtmlElementUtils.getWebElement(ru.sbtqa.tag.pagefactory.utils.HtmlElementUtils.getWebElement)

Example 2 with HtmlFindUtils

use of ru.sbtqa.tag.pagefactory.find.HtmlFindUtils in project page-factory-2 by sbtqa.

the class IndexPage method openedPage.

@ActionTitle("opened page")
public void openedPage(String page) throws ElementDescriptionException, ElementNotFoundException {
    HtmlFindUtils htmlFindUtils = Environment.getFindUtils();
    List<Link> links = htmlFindUtils.findList(null, "menu with list elements->toolbar");
    String attributeClass = ElementUtils.getElementByText(links, page).findElement(By.xpath("./..")).getAttribute("class");
    Assert.assertEquals("The path to element was compiled incorrectly.", "active", attributeClass);
}
Also used : HtmlFindUtils(ru.sbtqa.tag.pagefactory.find.HtmlFindUtils) Link(ru.yandex.qatools.htmlelements.element.Link) ActionTitle(ru.sbtqa.tag.pagefactory.annotations.ActionTitle)

Example 3 with HtmlFindUtils

use of ru.sbtqa.tag.pagefactory.find.HtmlFindUtils in project page-factory-2 by sbtqa.

the class ContactPage method findBlock.

@ActionTitle("check find block")
public void findBlock() {
    HtmlFindUtils htmlFindUtils = Environment.getFindUtils();
    checkType(htmlFindUtils.find("menu", MenuBlock.class), MenuBlock.class);
    checkType(htmlFindUtils.find("menu", HtmlElement.class), MenuBlock.class);
}
Also used : HtmlFindUtils(ru.sbtqa.tag.pagefactory.find.HtmlFindUtils) HtmlElement(ru.yandex.qatools.htmlelements.element.HtmlElement) MenuBlock(ru.sbtqa.tag.pagefactory.pages.htmlelements.blocks.MenuBlock) ActionTitle(ru.sbtqa.tag.pagefactory.annotations.ActionTitle)

Example 4 with HtmlFindUtils

use of ru.sbtqa.tag.pagefactory.find.HtmlFindUtils in project page-factory-2 by sbtqa.

the class HTMLPage method checkInputMask.

public void checkInputMask(String field, String mask) {
    WebElement element = ((HtmlFindUtils) Environment.getFindUtils()).find(field);
    String expectedText = element.getText();
    Assert.assertTrue("Text does not match the mask " + mask + ". The field contains the text: " + expectedText, isStringMatch(mask, expectedText));
}
Also used : HtmlFindUtils(ru.sbtqa.tag.pagefactory.find.HtmlFindUtils) WebElement(org.openqa.selenium.WebElement)

Example 5 with HtmlFindUtils

use of ru.sbtqa.tag.pagefactory.find.HtmlFindUtils in project page-factory-2 by sbtqa.

the class TableAbstract method selectRowByElement.

/**
 * Selects a row in a table by element value in a column. Checks all the fields with
 * the specified element name in order, until the search text is found in one of them.
 * If several elements are found with the search text, the element with the specified number will be selected.
 * If an element with the specified text and number is not found, an exception will be thrown.
 *
 * @param columnName column name
 * @param elementName element name
 * @param elementValue search text
 * @param serialNumber sequence number for selection of matches found (1, 2, 3 ...)
 * @param doubleClick {@code true}, if you need to make a double-click selection,
 * and {@code false} if single
 */
public void selectRowByElement(String columnName, String elementName, String elementValue, int serialNumber, boolean doubleClick) {
    int columnIndex = getColumnIndexByName(columnName);
    HtmlFindUtils findUtils = Environment.getFindUtils();
    try {
        List<BaseElement> cells = findUtils.findList(this, columnName);
        if (!cells.isEmpty()) {
            Class<?> cellType = cells.get(0).getClass();
            List<Field> fields = FieldUtils.getFieldsListWithAnnotation(cellType, ElementTitle.class);
            String elementXpath = fields.stream().filter(field -> field.getAnnotation(ElementTitle.class).value().equals(elementName)).findFirst().orElseThrow(() -> new AutotestError("No cell element with name found: " + elementName)).getAnnotation(FindBy.class).xpath();
            // to glue it under special conditions, excluding these symbols
            if (elementXpath.startsWith(".") || elementXpath.startsWith("(")) {
                elementXpath = elementXpath.replaceFirst("\\.?\\(?\\.?", "").replaceFirst("\\) ?\\[", "[");
            }
            String elementWithTextXpath = getColumnXpath(columnIndex) + elementXpath + format(TEXT_PART_XPATH_TEMPLATE, elementValue);
            List<WebElement> elements = this.findElements(By.xpath(elementWithTextXpath));
            click(ElementUtils.getElementByIndex(elements, serialNumber - 1), doubleClick);
        } else {
            throw new AutotestError("No column in the table was found: " + columnName);
        }
    } catch (ElementDescriptionException ex) {
        throw new AutotestError("Error finding element in table");
    } catch (ElementNotFoundException e) {
        throw new AutotestError(format("No cell element found with value: %s. Number: %s", elementValue, serialNumber));
    }
}
Also used : AutotestError(ru.sbtqa.tag.qautils.errors.AutotestError) ElementNotFoundException(ru.sbtqa.tag.pagefactory.exceptions.ElementNotFoundException) WebElement(org.openqa.selenium.WebElement) HtmlFindUtils(ru.sbtqa.tag.pagefactory.find.HtmlFindUtils) BaseElement(ru.sbtqa.tag.pagefactory.elements.BaseElement) Field(java.lang.reflect.Field) ElementDescriptionException(ru.sbtqa.tag.pagefactory.exceptions.ElementDescriptionException) ElementTitle(ru.sbtqa.tag.pagefactory.annotations.ElementTitle) FindBy(org.openqa.selenium.support.FindBy)

Aggregations

HtmlFindUtils (ru.sbtqa.tag.pagefactory.find.HtmlFindUtils)8 WebElement (org.openqa.selenium.WebElement)5 ActionTitle (ru.sbtqa.tag.pagefactory.annotations.ActionTitle)4 HtmlElement (ru.yandex.qatools.htmlelements.element.HtmlElement)2 TypifiedElement (ru.yandex.qatools.htmlelements.element.TypifiedElement)2 Field (java.lang.reflect.Field)1 FindBy (org.openqa.selenium.support.FindBy)1 ElementTitle (ru.sbtqa.tag.pagefactory.annotations.ElementTitle)1 BaseElement (ru.sbtqa.tag.pagefactory.elements.BaseElement)1 ElementSearchError (ru.sbtqa.tag.pagefactory.exception.ElementSearchError)1 ElementDescriptionException (ru.sbtqa.tag.pagefactory.exceptions.ElementDescriptionException)1 ElementNotFoundException (ru.sbtqa.tag.pagefactory.exceptions.ElementNotFoundException)1 MenuBlock (ru.sbtqa.tag.pagefactory.pages.htmlelements.blocks.MenuBlock)1 HtmlElementUtils.getWebElement (ru.sbtqa.tag.pagefactory.utils.HtmlElementUtils.getWebElement)1 AutotestError (ru.sbtqa.tag.qautils.errors.AutotestError)1 Button (ru.yandex.qatools.htmlelements.element.Button)1 Link (ru.yandex.qatools.htmlelements.element.Link)1 TextInput (ru.yandex.qatools.htmlelements.element.TextInput)1