I have this code
public static SelenideElement findElementByTitle(String elementName) throws IllegalAccessException {
Set<Field> annotated = new Reflections(lastInitialized, new FieldAnnotationsScanner()).getFieldsAnnotatedWith(ElementTitle.class);
for (Field field : annotated) {
ElementTitle annotation = field.getAnnotation(ElementTitle.class);
if (annotation.value().equals(elementName)) {
field.setAccessible(true);
SelenideElement el = (SelenideElement) field.get(page(lastInit));
return el;
}
}
throw new AutotestError("Element not found: " + elementName);
It worked just fine before I actually implemented inheritance and it appears that my code can't access annotated fields from parent class. If I set package access I get exceptions because of ambiguity (got several same annotations throughout different classes, for example the "Next" button).
Here's the code which sets lastInitialized and lastInit fields (PAGES_PACKAGE is just a string pointing to the package containing all of my page object classes)
public static void initPage(String pageName) throws Exception {
Set<Class<?>> annotated = new Reflections(PAGES_PACKAGE).getTypesAnnotatedWith(PageTitle.class);
for (Class classToInit : annotated) {
PageTitle annotation = (PageTitle) classToInit.getAnnotation(PageTitle.class);
if (annotation.value().equals(pageName)) {
classToInit.newInstance();
lastInitialized = substringAfter(classToInit.toString(), "class ");
lastInit = classToInit;
return;
}
}
throw new AutotestError("Can't find page to init: " + pageName);
}
What I want to do is I want to have a Main page which has all the general fields every other tab on the website does and to have all of my website's "tabs" inherit from it while being able to access parent fields as if they were my current page's.
Aucun commentaire:
Enregistrer un commentaire