Skip to content

Not able to call PageFactory with a Class (Only with "this") #76

Closed

Description

@lolemouine

This works :
PageFactory.initElements(new AppiumFieldDecorator(myDriver), this);

This is not Working :
PageFactory.initElements(new AppiumFieldDecorator(myDriver), MyClass.class);

Why?

Activity

  1. lolemouine commented on Aug 1, 2014

    @lolemouine
    Author

    PageFactory.initElements(new AppiumFieldDecorator(myDriver), TheClassImUsingRightNow.class);
    Or
    PageFactory.initElements(new AppiumFieldDecorator(myDriver), AnotherClass.class);
    wouldn't work...

  2. TikhomirovSergey commented on Aug 1, 2014

    @TikhomirovSergey
    Contributor

    Hi!

    You are using Selenium PageFactory class. It has no method with these parameters:
    FieldDecorator
    Class of Page Object.

    Please see here: https://github.com/SeleniumHQ/selenium/blob/master/java/client/src/org/openqa/selenium/support/PageFactory.java

    What does method that you are trying to invoke:

    1. It instantiates PageObject.class
    2. It decorates fields using DefaultFieldDecorator (!!!) //FindBy only with some invalid for native apps strategies such as cssSelector, linkText, ect.

    So. If you want to use AppiumFieldDecorator, you should prepare an instance of your PageObject.class whose fields have to be decorated.

    PageObject pageObject = new PageObject(someParams)
    PageFactory.initElements(new AppiumFieldDecorator(driver), pageObject);

    or

    public PageObject(someParams){
    //staff
    PageFactory.initElements(new AppiumFieldDecorator(driver), this);
    }
    
    
    
    //at automated test
    PageObject pageObject = new PageObject(someParams);
  3. TikhomirovSergey commented on Aug 1, 2014

    @TikhomirovSergey
    Contributor

    I am sorry for confusion :)
    I made a little improvement here: #68

    Decorator that I made is useful when browser, Android or iOS UI have different locators.
    So, if you don't want to multiply your classes:

    @AndroidFindBy
    @iOSFindBy
    @findby
    Webelement

    AppiumFieldDecorator decorates fields marked by @AndroidFindBy, @iOSFindBy and @findby too.

  4. TikhomirovSergey commented on Aug 1, 2014

    @TikhomirovSergey
    Contributor
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