I am starting a new project and creating the pageObjects using the PageFactory approach. I am facing an error that I’m not able to resolve so far, any help would be appreciated please.
instead of this: PageFactory.initElements(hook.getDriver(), this);
write as follow: PageFactory.initElements(new AppiumFieldDecorator(hook.getDriver()), this);
or, if you want to specify a maximum timeout when locating the element: PageFactory.initElements(new AppiumFieldDecorator(hook.getDriver(), timeout), this);
when the timeout variable is an int (like 15) or a Duration instance (like Duration.ofSeconds(15)) - depends on your client and its version.
the problem is that it is decorating the page object instance (“this”) with selenium’s decorator (the default) - you need to pass it appium’s decorator named: AppiumFieldDecorator and then it will know to look for @AndroidFindBy annotation and other mobile annotations.
like you can understand by the error, the PageFactory(the element’s proxy) tried to locate the element with the variable’s name (proceedBtn) which is the default behaviour and did not use the locator (button_proceed) at all. again, because it did not realize the annotation.
Thank you @ido_oserovitz for the fast and nice reply. I appreciate the explanation. I have implemented what you suggested, and now I’m facing another issue/error. The error log: gist:60481c6ef95fd5803d49ee5bb221a6f9 · GitHub
The statements where the error log is pointing at are where I call the PageObjects class in my Stepdefinition class:
public explorePage explorePage = new explorePage();
And the constructor of the PageObject:
public explorePage() {
PageFactory.initElements(new AppiumFieldDecorator(hook.getDriver()), this);
}
Edit: I believe this issue might be caused by Eclipse’s execution java version. I am trying to resolve it and will update the thread.
please provide more code and info, it is not enough. do not post only what you think is wrong, send more so we can really help.
for now, you get java.lang.NoSuchMethodException: jdk.proxy2.$Proxy17.proxyClassLookup()
and it looks like you call a method that does not exist. the constructor looks good and from the stack trace in the link you sent I can see that the constructor got invoked so maybe it is a different method call you do afterward in the test class.
some important things. the standard writing is to start class’ names with uppercase and variable’s names with lowercase.
this: public explorePage explorePage = new explorePage();
should be: public ExplorePage explorePage = new ExplorePage(); and the constructor should be with uppercase as well.
Issue resolved after upgrading the Local Java and IDE java and compiler version from Java 8 to Java 11. Thread can be closed now, thank you all for the help.