use of ru.sbtqa.tag.pagefactory.exception.ElementSearchError in project page-factory-2 by sbtqa.
the class HtmlFindUtils method findList.
/**
* Gets a list of elements by name or path
* <p>
* As a path, an enumeration of elements in a nested structure can be used
* through the separator "{@code ->}", for example:
* <ul>
* <li> element in the block: Block{@code ->}Element
* <li> element in the list with the sequence number 3: List{@code ->}3
* </ul>
* <p>
*
* @param <T> type of the returned element
* @param context current context - where to start searching for an element.
* Specify {@code null} if you need to perform a search in the context of
* the current page, or an element to search for
* @param name list name or path to it
* @return Returns a list from a page by name or path
* @throws ru.sbtqa.tag.pagefactory.exceptions.ElementDescriptionException Error get element by field
*/
public <T extends WebElement, E extends WebElement> List<E> findList(T context, String name) throws ElementDescriptionException {
try {
ComplexElement element;
Field field;
if (name.contains(ELEMENT_SEPARATOR)) {
int lastSeparatorIndex = name.lastIndexOf(ELEMENT_SEPARATOR);
element = findComplexElement(context, name.substring(0, lastSeparatorIndex), false);
String listName = name.substring(lastSeparatorIndex + ELEMENT_SEPARATOR.length());
field = getField(element.getElement(), listName);
} else {
element = new ComplexElement<>(context, name, false);
field = getField(context, name);
}
if (field == null) {
throw new ElementSearchError("Element list not found");
}
if (!field.getType().isAssignableFrom(List.class)) {
throw new IncorrectElementTypeError(format("The element was found, " + "but it is not a list. The search was performed along the way: %s", name));
}
return (List<E>) getElementByField(element, field);
} catch (ElementSearchError e) {
return (List<E>) TestIdUtils.findListWithEmptyResult(name);
}
}
use of ru.sbtqa.tag.pagefactory.exception.ElementSearchError in project page-factory-2 by sbtqa.
the class HtmlFindUtils method findComplexElement.
private <T extends WebElement> ComplexElement findComplexElement(T context, String name, boolean wait) {
ComplexElement<T> element = new ComplexElement<>(context, name, wait);
try {
for (; element.getCurrentPosition() < element.getElementPath().size(); element.setCurrentPosition(element.getCurrentPosition() + 1)) {
Field field = getField(element.getElement(), element.getCurrentName());
if (field == null) {
throw new ElementSearchError("No element declared on page " + formErrorMessage(element));
}
findElement(field, element);
}
if (element.getCurrentPosition() > 0) {
element.setCurrentPosition(element.getCurrentPosition() - 1);
}
} catch (AutotestError | IllegalArgumentException | ElementDescriptionException ex) {
throw new ElementSearchError("Element " + formErrorMessage(element), ex);
}
return element;
}
use of ru.sbtqa.tag.pagefactory.exception.ElementSearchError in project page-factory-2 by sbtqa.
the class HtmlReflection method executeMethodByTitleInBlock.
/**
* Execute method with one or more parameters inside of the given block
* element
*
* @param blockPath block title, or a block chain string separated with
* {@code ->} symbols
* @param actionTitle title of the action to execute
* @param parameters parameters that will be passed to method
*/
public void executeMethodByTitleInBlock(String blockPath, String actionTitle, Object... parameters) {
try {
HtmlElement block = ((HtmlFindUtils) Environment.getFindUtils()).find(blockPath, HtmlElement.class);
executeMethodByTitle(block, actionTitle, parameters);
} catch (ElementSearchError ex) {
throw new ElementSearchError(format("Block not found by path '%s'", blockPath), ex);
}
}
Aggregations