use of ru.sbtqa.tag.pagefactory.elements.BaseElement in project page-factory-2 by sbtqa.
the class SelectAbstract method selectByValue.
/**
* Selects an option for the text value in the specified element
*
* @param value the value to be selected
* @param element the element within which the search will occur
*/
public void selectByValue(String value, String element) throws AutotestError {
open();
List<? extends BaseElement> listOp = getOptions();
for (BaseElement op : listOp) {
if (value.equals(op.getElement(element).getText())) {
op.click();
return;
}
}
close();
throw new AutotestError(format(NOT_FOUND_OPTION_IN_ELEMENT_TEMPLATE, value, element));
}
use of ru.sbtqa.tag.pagefactory.elements.BaseElement in project page-factory-2 by sbtqa.
the class SelectAbstract method selectByIndex.
/**
* Select an option by index
*
* @param i option index
*/
public void selectByIndex(int i) {
open();
BaseElement option = ElementUtils.getElementByIndex(getOptions(), i);
if (!option.isEnabled()) {
throw new AutotestError(String.format(ERROR_DISABLED_TEMPLATE, option.getText()));
}
option.click();
}
use of ru.sbtqa.tag.pagefactory.elements.BaseElement 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));
}
}
use of ru.sbtqa.tag.pagefactory.elements.BaseElement in project page-factory-2 by sbtqa.
the class AccordionSteps method checkElements.
/**
* For complex accordion.
* If there are elements within the complex element of an accordion, their text content can be checked by this method
*
* @param accordionName accordion name
* @param expectedTable expected accordion elements values
* @return Returns itself
*/
public AccordionSteps checkElements(String accordionName, DataTable expectedTable) {
Map<String, String> expectedMap = expectedTable.asMap(String.class, String.class);
BaseElement content = getElement(accordionName).getContent();
expectedMap.forEach((element, elementValue) -> {
String actualText = content.getElement(element).getText();
checkText(actualText, elementValue, SearchStrategy.EQUALS);
});
return this;
}
Aggregations