use of ru.sbtqa.tag.pagefactory.annotations.ElementTitle in project page-factory-2 by sbtqa.
the class ExceptionAspect method getErrorText.
private String getErrorText(String throwMessage) throws PageInitializationException, IllegalArgumentException, IllegalAccessException {
String errorText = "";
Field[] fields = PageContext.getCurrentPage().getClass().getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
Object currentObject = null;
if (PageContext.getCurrentPage() != null) {
currentObject = field.get(PageContext.getCurrentPage());
}
if (null != currentObject && throwMessage.contains(field.getName())) {
for (Annotation annotation : field.getAnnotations()) {
if (annotation instanceof ElementTitle) {
errorText = "There is no element with title == " + ((ElementTitle) annotation).value();
break;
}
}
}
}
return errorText;
}
use of ru.sbtqa.tag.pagefactory.annotations.ElementTitle in project page-factory-2 by sbtqa.
the class PageManager method cachePages.
public static void cachePages() {
for (Class<?> page : getAllClasses()) {
List<Field> fields = FieldUtilsExt.getDeclaredFieldsWithInheritance(page);
Map<Field, String> fieldsMap = new HashMap<>();
for (Field field : fields) {
ElementTitle titleAnnotation = field.getAnnotation(ElementTitle.class);
if (titleAnnotation != null) {
fieldsMap.put(field, titleAnnotation.value());
} else {
fieldsMap.put(field, field.getName());
}
}
PAGES_REPOSITORY.get().put((Class<? extends Page>) page, fieldsMap);
}
}
use of ru.sbtqa.tag.pagefactory.annotations.ElementTitle in project page-factory-2 by sbtqa.
the class SetupStepDefs method cachePages.
private void cachePages() {
Set<Class<?>> allClasses = new HashSet();
allClasses.addAll(getAllClasses());
for (Class<?> page : allClasses) {
List<Field> fields = FieldUtilsExt.getDeclaredFieldsWithInheritance(page);
Map<Field, String> fieldsMap = new HashMap<>();
for (Field field : fields) {
Class<?> fieldType = field.getType();
if (fieldType.equals(WebElement.class)) {
ElementTitle titleAnnotation = field.getAnnotation(ElementTitle.class);
if (titleAnnotation != null) {
fieldsMap.put(field, titleAnnotation.value());
} else {
fieldsMap.put(field, field.getName());
}
}
}
PageFactory.getPageRepository().put((Class<? extends Page>) page, fieldsMap);
}
}
Aggregations