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

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

Closed
lolemouine opened this issue Aug 1, 2014 · 4 comments
Closed

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

lolemouine opened this issue Aug 1, 2014 · 4 comments

Comments

@lolemouine
Copy link

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

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

Why?

@lolemouine
Copy link
Author

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

@TikhomirovSergey
Copy link
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);

@TikhomirovSergey
Copy link
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.

@TikhomirovSergey
Copy link
Contributor

#73

@Jonahss Jonahss closed this as completed Aug 8, 2014
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

3 participants