Skip to content

Page factory list element not initialized when parameterized by generic type #1150

Description

@JamesSassano

Description

Given the following class (We have a base screen class that is used for Android and iOS that each specify T as AndroidElement and IOSElement, respectively, where we want to retain the specific platform element type):

publicclassScreenWithLists<TextendsMobileElement> {
publicList<MobileElement> listME;
publicList<T> listT;
}

and initialization with:

PageFactory.initElements(newAppiumFieldDecorator(driver),
newScreenWithLists<MobileElement>()); // Or AndroidElement or IOSElement

The "listT" field does not get initialized as it fails the isDecoratableList check in AppiumFieldDecorator's DefaultFieldDecorator implementation when checking the list's type is one of "availableElementClasses".

Environment

  • appium java client build version: 6.1.0
  • selenium client build version: 3.12

Details

This generic type may be able to be checked with an additional bounds check in AppiumFieldDecorator's isDecoratableList:

 if ((listType instanceof TypeVariable) &&
Arrays.asList(((TypeVariable<?>) listType).getBounds())
.stream().anyMatch(item -> availableElementClasses.contains(item))) {
return true;
}

Testing

https://github.com/appium/java-client/blob/master/src/test/java/io/appium/java_client/pagefactory_tests/GenericTest.java
could update the Supplier to:

TempGenericPage<?> page = newTempGenericPage<>();
PageFactory
.initElements(newAppiumFieldDecorator(newMockWebDriver()),
page);
returnnull != page.getItems();

Related issue:

#368

Code To Reproduce Issue [ Good To Have ]

publicclassListParameterReproductionTest {
publicstaticclassScreenWithLists<T> {
publicList<MobileElement> listME;
publicList<T> listT;
}
publicstaticvoidmain(String[] args) {
SearchContextmockSearchContext = newSearchContext() {
@Overridepublic <TextendsWebElement> List<T> findElements(Byby) {
returnnull;
}
@Overridepublic <TextendsWebElement> TfindElement(Byby) {
returnnull;
}
};
ScreenWithLists<MobileElement> screen = newScreenWithLists<MobileElement>();
PageFactory.initElements(newAppiumFieldDecorator(mockSearchContext), screen);
assertNotNull(screen.listME);
assertNotNull(screen.listT);
}
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions