java-client icon indicating copy to clipboard operation
java-client copied to clipboard

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

Open lolemouine opened this issue 12 years ago • 4 comments

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

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

Why?

lolemouine avatar Aug 01 '14 18:08 lolemouine

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

lolemouine avatar Aug 01 '14 19:08 lolemouine

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

TikhomirovSergey avatar Aug 01 '14 20:08 TikhomirovSergey

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.

TikhomirovSergey avatar Aug 01 '14 20:08 TikhomirovSergey

#73

TikhomirovSergey avatar Aug 01 '14 20:08 TikhomirovSergey