PageObjects gets elements API instead of element API
saikrishna321 opened this issue · 18 comments
@TikhomirovSergey need help on this
Works fine
@HowToUseLocators(androidAutomation = CHAIN)
@AndroidFindBySet({
@AndroidFindBy(xpath = "(.//*[@resource-id='org.wordpress.android:id/note_content_container'])[position()=2]"),
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"org.wordpress.android:id/note_subject\")")
}) //gets the third text from the note_subject view
Does not work
@HowToUseLocators(androidAutomation = CHAIN)
@AndroidFindBySet({
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"org.wordpress.android:id/note_content_container\").enabled(true).instance(2)"),
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"org.wordpress.android:id/note_subject\")")
}) //return the first text from the view
https://gist.github.com/anonymous/d4440cab5e3213f9084498471201cd84
The above works fine, when we cast AndroidDriver
((AndroidDriver) driver).findElementByAndroidUIAutomator("new UiSelector().resourceId(\"org.wordpress.android:id/note_subject\").enabled(true).instance(2)").getText()
https://gist.github.com/anonymous/3b1fcc5761c370a1025d52c42b60b9fd
@saikrishna321
Please remove @AndroidFindBySet
and check the result and use only AndroidFindBy :)
@TikhomirovSergey giving it a try now.. What does @AndroidFindBySet do ?
It makes AndroidFindBy repeatable.
http://docs.oracle.com/javase/tutorial/java/annotations/repeating.html
@TikhomirovSergey still the same, it just gets the default first locator's text value
@saikrishna321
https://github.com/appium/java-client/blob/master/src/main/java/io/appium/java_client/pagefactory/AndroidFindBy.java#L34
Also if it is the chain by default you may not define
@HowToUseLocators(androidAutomation = CHAIN)
Please take a look at the updated WIKI chapter
@saikrishna321
What happens when you try to
driver.findElementByAndroidUIAutomator("new UiSelector().resourceId(\"org.wordpress.android:id/note_subject\").enabled(true).instance(2)")
.findElementByAndroidUIAutomator("new UiSelector().resourceId(\"org.wordpress.android:id/note_subject\")")
?
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"org.wordpress.android:id/note_content_container\").enabled(true).instance(2)"),
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"org.wordpress.android:id/note_subject\")")
public MobileElement getNotification;
With this as well the logs are same.
Here it picks the command with instance(3) https://gist.github.com/anonymous/cc08201899d52d47322604d3954817a3#file-updated-gist-with-androidfindby-L1132
and still looks for all elements
https://gist.github.com/anonymous/cc08201899d52d47322604d3954817a3#file-updated-gist-with-androidfindby-L1148-L1161
driver.findElementByAndroidUIAutomator("new UiSelector().resourceId("org.wordpress.android:id/note_subject").enabled(true).instance(2)").findElementByAndroidUIAutomator("new UiSelector().resourceId("org.wordpress.android:id/note_subject")")
It gives the Text at the Third view which is expected :)
So does this code works well
driver.findElementByAndroidUIAutomator("new UiSelector().resourceId(\"org.wordpress.android:id/note_subject\").enabled(true).instance(2)")
.findElementByAndroidUIAutomator("new UiSelector().resourceId(\"org.wordpress.android:id/note_subject\")")
?
Ok. Has the same happened before (v<5.0.0-BETAx)? If there is a client bug then it may be the old problem that should be fixed
@TikhomirovSergey
This works
((AndroidDriver) driver).findElementByAndroidUIAutomator("new UiSelector().resourceId(\"org.wordpress.android:id/note_content_container\").enabled(true).instance(2)").
findElement(MobileBy.AndroidUIAutomator("new UiSelector().resourceId(\"org.wordpress.android:id/note_subject\")")).getText();
https://gist.github.com/saikrishna321/a156e5c88a9787c0794bca7646ec47cf
Yah, i just tried with 4.1.2 and its the same. Chaining with unique ID's works, but with uiAutomation does not. Looks like we need to fix
Yep. I will try to search for the root cause on the 1 Jan. For now please use xpath instead.
Cheers, this is required for the appium workshop(http://thoughtworks-bangalore.github.io/vodQA-Shots/) so will wait for the fix
@saikrishna321
... and for your case it is enough
@AndroidFindBy(xpath = "(.//*[@resource-id='org.wordpress.android:id/note_content_container'])[position()=2]"),
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"org.wordpress.android:id/note_subject\")")
MobileElement element;
@TikhomirovSergey its calling elements instead of element api, can you please help in pointing where we call this api
yes.
It is here
https://github.com/appium/java-client/blob/master/src/main/java/io/appium/java_client/pagefactory/AppiumElementLocator.java#L157
I really think that root cause is here. But I can check it only tomorrow or on the 1 Jan.
myself and @SrinivasanTarget are looking at it, if we break through will send a PR
@saikrishna321
There were few reasons why it was designed that way. But I think it is outdated implementation for now.
myself and @SrinivasanTarget are looking at it, if we break through will send a PR
Ok.
But please keep it in mind that it should be NowSuchElementException-safe till waiting time is expired.
Also please take a look at these classes from Selenium:
ByAll
ByChained
Could you please try this
driver.findElenent(new ByChained(...))
using your AndroidUIAtomator locators?