You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
iOSFindBy & AndroidFindBy annotations are ignored #211
I've been trying for a couple of days to get iOSFindBy & AndroidFindBy annotations working with page objects and the PageFactory. I've tried versions 2.2.0 and 3.0.0 of the java-client and tests for Android and iOS, all with the same result - which is the same as not including any annotations.
Here is a truncated version of one of my page objects
@TestpublicvoidtestHomeIsValid() {
homePhonePage = newHomePhonePage(driver);
globalNavPage = newGlobalNavigationPage(driver);
homePhonePage.clickHamburgerMenu(); //FAILS HERE because element was not foundglobalNavPage.clickHome();
}
When I debug into PageFactory.initElements, I see [unknown locator] for each property that is a WebElement. Then the PageFactory defaults to looking for each page object's property name as the id or name of the WebElement and fails to find anything.
I suspect "I'm doing it wrong" but I can't figure out where. It is behaving as if the annotations are not even there.
I also dug a bit deeper into the debugger for the particular field I've included above as it's being decorated by the PageFactory and it shows no annotations (I'm not sure if it should):
Appuim features allow to implement one page object for Android/iOS/browser testing. Please look at this
@iOSFindBy(locator_for_ios) //this locater is used when here is iOS native content@AndroidFindBy(locator_for_android)//this locator is used when here //is Android native content@FindBy(locator_for_HTML)//this locator is used when here mobile //or desktop browser or webviewprivateWebElementmyFavoritesCountLabel;
@TikhomirovSergey - I understand that I can use a single page object to test both platforms but I've found in this particular instance it didn't work out well because the implementations are somewhat different and evolving at different rates.
Here is the Android page object (same as iOS in this instance but in a different package):
ok. Now it is clear. Is your app hybrid? Appium-specific annotations were designed for native contents. What does return .getContext() method before your test is failed?
I tried switching to node server (instead of Appium.app) and got the same results. It's still trying to use the property name of the page object to find elements instead of using the values provided in the annotations.
@TikhomirovSergey - thanks for the update and your speedy fix. How long is typical for a merge? Our tiny team of two is somewhat blocked by this issue.
@Jonahss - our current gradle build script pulls from the Maven repo. I could probably tweak it to download the source and compile it if you weren't planning to do a release for a while. If it's relatively effortless to do a release, that would accelerate things on my side.
@justintilson Yeah I can do a release :)
It's relatively effortless compared to gardening in my backyard. But is an incredible amount of effort compared to using npm :P
one question. Do I need to change the context of the driver before I try to locate webview elements (hybrid app - like FB login) by using Page Objects/Factory as mentioned above?
FindBy(locator_for_HTML)//this locator is used when here mobile
//or desktop browser or webview
private WebElement myFavoritesCountLabel;
Activity
Simon-Kaz commentedon Jul 1, 2015
Hey, could you post your capabilities as well? I've been using page factory extensively and haven't encountered this issue.
justintilson commentedon Jul 1, 2015
outputs for an Android test:
Capabilities [{networkConnectionEnabled=true, desired={}, platformVersion=4.4.4, warnings={}, webStorageEnabled=false, locationContextEnabled=false, browserName=Android, takesScreenshot=true, javascriptEnabled=true, databaseEnabled=false, deviceName=192.168.56.101:5555, platform=LINUX}]
and for an iOS test:
Capabilities [{networkConnectionEnabled=false, desired={}, warnings={}, webStorageEnabled=false, locationContextEnabled=false, browserName=iOS, takesScreenshot=true, javascriptEnabled=true, databaseEnabled=false, platform=MAC}]
I also dug a bit deeper into the debugger for the particular field I've included above as it's being decorated by the PageFactory and it shows no annotations (I'm not sure if it should):
TikhomirovSergey commentedon Jul 1, 2015
@justintilson Hi!
Is it native app? Maybe hybrid. Maybe you are trying to run test with mobile browser?
TikhomirovSergey commentedon Jul 1, 2015
Are you tryng to use iOSFindBy for Android
?
Please improve your page object as follows
What the result?
justintilson commentedon Jul 1, 2015
@TikhomirovSergey, I'm testing native apps on Android and iOS.
I have separate tests and page objects for Android and iOS and use the appropriate @findby in each.
justintilson commentedon Jul 1, 2015
Here are the desired capabilities that are passed into the Android driver:
and for the iOS
justintilson commentedon Jul 1, 2015
And if it helps:
TikhomirovSergey commentedon Jul 1, 2015
Ok. If I clearly understand you
Appuim features allow to implement one page object for Android/iOS/browser testing. Please look at this
Ok. Is this used with Android
?
TikhomirovSergey commentedon Jul 1, 2015
...I am just trying to understand your problem and usecase :)
justintilson commentedon Jul 1, 2015
@TikhomirovSergey - I understand that I can use a single page object to test both platforms but I've found in this particular instance it didn't work out well because the implementations are somewhat different and evolving at different rates.
Here is the Android page object (same as iOS in this instance but in a different package):
TikhomirovSergey commentedon Jul 1, 2015
ok. Now it is clear. Is your app hybrid? Appium-specific annotations were designed for native contents. What does return .getContext() method before your test is failed?
justintilson commentedon Jul 1, 2015
System.out.println(driver.getContext());
prints: NATIVE_APP
TikhomirovSergey commentedon Jul 1, 2015
Ok. Is it possible that your project is still depending on java_client 2.2.0 or lower? Please look at your dependencies hierarchy.
justintilson commentedon Jul 1, 2015
I thought that might have had something to do with it so I upgraded yesterday. Here is my build.gradle file:
and the gradle cache:
TikhomirovSergey commentedon Jul 1, 2015
And when you are running
it is printing
Am I right? It interesting where is platformName = "Android".
1 remaining item
justintilson commentedon Jul 1, 2015
I changed the 'platformName' desired capability to 'platform' with no difference and then tried both platform and platformName with the same result.
Here is the DesiredCapabilities instance that is passed to the AndroidDriver's constructor:
and this is how they read after the driver has been instantiated:
I'm not sure where LINUX is coming from but it's not something I seem to be able to control.
justintilson commentedon Jul 2, 2015
I tried switching to node server (instead of Appium.app) and got the same results. It's still trying to use the property name of the page object to find elements instead of using the values provided in the annotations.
TikhomirovSergey commentedon Jul 6, 2015
@justintilson The PR is proposed and now it is waiting for the merging.
justintilson commentedon Jul 6, 2015
@TikhomirovSergey - thanks for the update and your speedy fix. How long is typical for a merge? Our tiny team of two is somewhat blocked by this issue.
TikhomirovSergey commentedon Jul 6, 2015
It is depending on @Jonahss
Merge pull request #213 from TikhomirovSergey/#211_#184-fix
Jonahss commentedon Jul 6, 2015
@justintilson merged!
Are you ok compiling on your own from this repo? Or would you prefer we do a full release to the Maven Central Repository?
justintilson commentedon Jul 6, 2015
@Jonahss - our current gradle build script pulls from the Maven repo. I could probably tweak it to download the source and compile it if you weren't planning to do a release for a while. If it's relatively effortless to do a release, that would accelerate things on my side.
Jonahss commentedon Jul 6, 2015
@justintilson Yeah I can do a release :)
It's relatively effortless compared to gardening in my backyard. But is an incredible amount of effort compared to using npm :P
I'll start running the test suite now.
Jonahss commentedon Jul 6, 2015
@justintilson Ok, released version 3.1.0
justintilson commentedon Jul 6, 2015
It works! I tested on both Android and iOS. @TikhomirovSergey, @Jonahss Thanks so much for moving this issue through so quickly!
Jonahss commentedon Jul 6, 2015
Yay!
On Mon, Jul 6, 2015 at 3:57 PM, Justin Tilson notifications@github.com
wrote:
TikhomirovSergey commentedon Jul 7, 2015
I'm happy :)
umer-ali-khan commentedon May 17, 2016
one question. Do I need to change the context of the driver before I try to locate webview elements (hybrid app - like FB login) by using Page Objects/Factory as mentioned above?
FindBy(locator_for_HTML)//this locator is used when here mobile
//or desktop browser or webview
private WebElement myFavoritesCountLabel;