Search in sources :

Example 1 with ElementTitle

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;
}
Also used : Field(java.lang.reflect.Field) ElementTitle(ru.sbtqa.tag.pagefactory.annotations.ElementTitle) Annotation(java.lang.annotation.Annotation)

Example 2 with ElementTitle

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);
    }
}
Also used : Field(java.lang.reflect.Field) ElementTitle(ru.sbtqa.tag.pagefactory.annotations.ElementTitle)

Example 3 with ElementTitle

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);
    }
}
Also used : Field(java.lang.reflect.Field) HashMap(java.util.HashMap) ElementTitle(ru.sbtqa.tag.pagefactory.annotations.ElementTitle) HashSet(java.util.HashSet)

Aggregations

Field (java.lang.reflect.Field)3 ElementTitle (ru.sbtqa.tag.pagefactory.annotations.ElementTitle)3 Annotation (java.lang.annotation.Annotation)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1