Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JamesSassano opened this issue Jun 4, 2019 · 0 comments

Comments

@JamesSassano
Copy link
Contributor

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):

    public class ScreenWithLists<T extends MobileElement> {
        public List<MobileElement> listME;
        public List<T> listT;
    }

and initialization with:

    PageFactory.initElements(new AppiumFieldDecorator(driver),
            new ScreenWithLists<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 = new TempGenericPage<>();
    PageFactory
            .initElements(new AppiumFieldDecorator(new MockWebDriver()),
                    page);
    return null != page.getItems();

Related issue:

#368

Code To Reproduce Issue [ Good To Have ]

public class ListParameterReproductionTest {
    public static class ScreenWithLists<T> {
        public List<MobileElement> listME;
        public List<T> listT;
    }

    public static void main(String[] args) {
        SearchContext mockSearchContext = new SearchContext() {
            @Override
            public <T extends WebElement> List<T> findElements(By by) {
                return null;
            }

            @Override
            public <T extends WebElement> T findElement(By by) {
                return null;
            }
        };

        ScreenWithLists<MobileElement> screen = new ScreenWithLists<MobileElement>();
        PageFactory.initElements(new AppiumFieldDecorator(mockSearchContext), screen);
        assertNotNull(screen.listME);
        assertNotNull(screen.listT);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant