Skip to content

PageObjects gets elements API instead of element API #549

Closed

Description

@saikrishna321

@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

Activity

  1. TikhomirovSergey commented on Dec 30, 2016

    @TikhomirovSergey
    Contributor

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

  2. saikrishna321 commented on Dec 30, 2016

    @saikrishna321
    MemberAuthor

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

  3. TikhomirovSergey commented on Dec 30, 2016

    @TikhomirovSergey
    Contributor
  4. saikrishna321 commented on Dec 30, 2016

    @saikrishna321
    MemberAuthor

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

  5. saikrishna321 commented on Dec 30, 2016

    @saikrishna321
    MemberAuthor
  6. TikhomirovSergey commented on Dec 30, 2016

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

  7. TikhomirovSergey commented on Dec 30, 2016

    @TikhomirovSergey
    Contributor

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

    ?

  8. saikrishna321 commented on Dec 30, 2016

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

  9. TikhomirovSergey commented on Dec 30, 2016

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

  10. saikrishna321 commented on Dec 30, 2016

    @saikrishna321
    MemberAuthor

    @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

  11. TikhomirovSergey commented on Dec 30, 2016

    @TikhomirovSergey
    Contributor

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

  12. added this to the 5.0.0 milestone on Dec 30, 2016
  13. saikrishna321 commented on Dec 30, 2016

    @saikrishna321
    MemberAuthor

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

  14. TikhomirovSergey commented on Dec 30, 2016

    @TikhomirovSergey
    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;
  15. saikrishna321 commented on Dec 30, 2016

    @saikrishna321
    MemberAuthor

    @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

  16. TikhomirovSergey commented on Dec 30, 2016

    @TikhomirovSergey
    Contributor

    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.

  17. saikrishna321 commented on Dec 30, 2016

    @saikrishna321
    MemberAuthor

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

  18. TikhomirovSergey commented on Dec 30, 2016

    @TikhomirovSergey
    Contributor

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

  19. TikhomirovSergey commented on Dec 30, 2016

    @TikhomirovSergey
    Contributor

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

  20. changed the title [-]PageObjects not working on uiAutomation selector[/-] [+]PageObjects gets elements API instead of element API[/+] on Dec 30, 2016
  21. added a commit that references this issue on Jan 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions