Not able to call PageFactory with a Class (Only with "this")
This works : PageFactory.initElements(new AppiumFieldDecorator(myDriver), this);
This is not Working : PageFactory.initElements(new AppiumFieldDecorator(myDriver), MyClass.class);
Why?
PageFactory.initElements(new AppiumFieldDecorator(myDriver), TheClassImUsingRightNow.class); Or PageFactory.initElements(new AppiumFieldDecorator(myDriver), AnotherClass.class); wouldn't work...
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:
- It instantiates PageObject.class
- 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);
I am sorry for confusion :) I made a little improvement here: https://github.com/appium/java-client/pull/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.
#73