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

PageObjects gets elements API instead of element API #549

Closed
saikrishna321 opened this issue Dec 30, 2016 · 18 comments
Closed

PageObjects gets elements API instead of element API #549

saikrishna321 opened this issue Dec 30, 2016 · 18 comments
Assignees
Milestone

Comments

@saikrishna321
Copy link
Member

saikrishna321 commented Dec 30, 2016

@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

@TikhomirovSergey
Copy link
Contributor

@saikrishna321
Please remove @AndroidFindBySet and check the result and use only AndroidFindBy :)

@saikrishna321
Copy link
Member Author

@TikhomirovSergey giving it a try now.. What does @AndroidFindBySet do ?

@TikhomirovSergey
Copy link
Contributor

It makes AndroidFindBy repeatable.
http://docs.oracle.com/javase/tutorial/java/annotations/repeating.html

@saikrishna321
Copy link
Member Author

@TikhomirovSergey still the same, it just gets the default first locator's text value

@saikrishna321
Copy link
Member Author

@TikhomirovSergey
Copy link
Contributor

@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

@TikhomirovSergey
Copy link
Contributor

TikhomirovSergey commented Dec 30, 2016

@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\")")

?

@saikrishna321
Copy link
Member Author

 @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 :)

@TikhomirovSergey
Copy link
Contributor

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

@saikrishna321
Copy link
Member Author

saikrishna321 commented Dec 30, 2016

@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

@TikhomirovSergey
Copy link
Contributor

Yep. I will try to search for the root cause on the 1 Jan. For now please use xpath instead.

@TikhomirovSergey TikhomirovSergey self-assigned this Dec 30, 2016
@TikhomirovSergey TikhomirovSergey added this to the 5.0.0 milestone Dec 30, 2016
@saikrishna321
Copy link
Member Author

saikrishna321 commented Dec 30, 2016

Cheers, this is required for the appium workshop(http://thoughtworks-bangalore.github.io/vodQA-Shots/) so will wait for the fix

@TikhomirovSergey
Copy link
Contributor

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

@saikrishna321
Copy link
Member Author

@TikhomirovSergey its calling elements instead of element api, can you please help in pointing where we call this api

https://gist.github.com/anonymous/cc08201899d52d47322604d3954817a3#file-updated-gist-with-androidfindby-L1132

@TikhomirovSergey
Copy link
Contributor

TikhomirovSergey commented Dec 30, 2016

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.

@saikrishna321
Copy link
Member Author

myself and @SrinivasanTarget are looking at it, if we break through will send a PR

@TikhomirovSergey
Copy link
Contributor

@saikrishna321
There were few reasons why it was designed that way. But I think it is outdated implementation for now.

@TikhomirovSergey
Copy link
Contributor

TikhomirovSergey commented Dec 30, 2016

@saikrishna321

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?

@saikrishna321 saikrishna321 changed the title PageObjects not working on uiAutomation selector PageObjects gets elements API instead of element API Dec 30, 2016
@TikhomirovSergey TikhomirovSergey mentioned this issue Jan 1, 2017
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants