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

Is it possible to add a way to change the root of the DataMatcher? #821

Open
Scrubles opened this issue Oct 5, 2022 · 13 comments
Open

Is it possible to add a way to change the root of the DataMatcher? #821

Scrubles opened this issue Oct 5, 2022 · 13 comments

Comments

@Scrubles
Copy link

Scrubles commented Oct 5, 2022

I'm trying to select a item on the dropdown of an AutoCompleteTextView. First I tried with the UiAutomator2, but there was nothing available there to make it work, then I tried with this library, but I stopped at the same point. I made it work running Espresso directly on my app, but I needed to use the method inRoot(isPlatformPopup()), which isn't available here, is it possible to add a way to call it?

I tried to call the inAdapterView, but I think it's 2 different things, and it didn't work.

@KazuCocoa
Copy link
Member

Maybe https://developer.android.com/reference/androidx/test/espresso/matcher/RootMatchers ?
Then I think currently this driver does not have it yet.

@Scrubles
Copy link
Author

Scrubles commented Oct 6, 2022

Do you if there's any other way to find elements on popups?

@mykola-mokhnach
Copy link
Contributor

Have you tried to use -android viewmatcher locators?

@KazuCocoa
Copy link
Member

First I tried with the UiAutomator2, but there was nothing available there to make it work

so, potentially this does not help, but you could use the below in an espresso session:
https://github.com/appium/appium-espresso-driver#mobile-uiautomator
https://github.com/appium/appium-espresso-driver#mobile-uiautomatorpagesource

@mykola-mokhnach
Copy link
Contributor

After v2.11.0 is is possible to provide root matchers to -android viewmatcher locators. See #822

@Scrubles
Copy link
Author

I don't know if I should reopen this issue or create a new one.
Using the root matcher, I was able to find the element, but when I try to click on it, I receive this Exception.

[debug] [EspressoDriver@8d20 (f832bd3b)] Matched '/session/f832bd3b-3a58-4794-ae71-9c1d0bab2867/element' to command name 'findElement'
[debug] [EspressoDriver@8d20 (f832bd3b)] Proxying [POST /session/f832bd3b-3a58-4794-ae71-9c1d0bab2867/element] to [POST http://127.0.0.1:8300/session/e0831ec4-9e99-4e80-8b99-262e681d7e17/element] with body: {"using":"-android viewmatcher","value":"{"class":"androidx.test.espresso.matcher.ViewMatchers","name":"withText","args":["27002628 - MTZ"],"scope":{"class":"androidx.test.espresso.matcher.RootMatchers","name":"isPlatformPopup"}}"}
[debug] [EspressoDriver@8d20 (f832bd3b)] Got response with status 200: {"id":"fde42c3e-4d77-46a2-93b8-4bfa6ce46c21","sessionId":"e0831ec4-9e99-4e80-8b99-262e681d7e17","value":{"ELEMENT":"82ea4f80-3cfc-4af5-b8a8-e24c55b165be"}}
[EspressoDriver@8d20 (f832bd3b)] Replacing sessionId e0831ec4-9e99-4e80-8b99-262e681d7e17 with f832bd3b-3a58-4794-ae71-9c1d0bab2867
[HTTP] <-- POST /session/f832bd3b-3a58-4794-ae71-9c1d0bab2867/element 200 85 ms - 232
[HTTP]
[debug] [HTTP] Request idempotency key: de91e231-c54e-4cb5-8710-13e08790c007
[HTTP] --> POST /session/f832bd3b-3a58-4794-ae71-9c1d0bab2867/element/82ea4f80-3cfc-4af5-b8a8-e24c55b165be/click
[HTTP] {}
[EspressoDriver@8d20 (f832bd3b)] Driver proxy active, passing request on via HTTP proxy
[debug] [EspressoDriver@8d20 (f832bd3b)] Matched '/session/f832bd3b-3a58-4794-ae71-9c1d0bab2867/element/82ea4f80-3cfc-4af5-b8a8-e24c55b165be/click' to command name 'click'
[debug] [EspressoDriver@8d20 (f832bd3b)] Proxying [POST /session/f832bd3b-3a58-4794-ae71-9c1d0bab2867/element/82ea4f80-3cfc-4af5-b8a8-e24c55b165be/click] to [POST http://127.0.0.1:8300/session/e0831ec4-9e99-4e80-8b99-262e681d7e17/element/82ea4f80-3cfc-4af5-b8a8-e24c55b165be/click] with body: {}
[EspressoDriver@8d20 (f832bd3b)] Got response with status 500: {"id":"565faf9b-8b19-42c9-a18d-270daa081f92","sessionId":"e0831ec4-9e99-4e80-8b99-262e681d7e17","value":{"error":"unknown error","message":"androidx.test.espresso.NoMatchingViewException...

I think it's trying to find element in the old scope.

Is it possible to add the scope to the DataMatcher as well?

Also, I think there is an error on ViewFinder.kt line 184:

getViews(root, matcherJson.query.matcher as Matcher<View>, findOne, matcherJson.query.scope as Matcher<Root>)

The scope should be Matcher? to allow nullable, shouldn't it?

@mykola-mokhnach
Copy link
Contributor

Could you provide the full stack trace?

@mykola-mokhnach
Copy link
Contributor

Also feel free to provide fixes - I don't have a possibility to test changes with a real app

@Scrubles
Copy link
Author

That's all I have, how do I get the full stacktrace?

[EspressoDriver@8d20 (f832bd3b)] Got response with status 500: {"id":"565faf9b-8b19-42c9-a18d-270daa081f92","sessionId":"e0831ec4-9e99-4e80-8b99-262e681d7e17","value":{"error":"unknown error","message":"androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching: Looked for element with View androidx.appcompat.widget.AppCompatTextView{1616b22 V.ED..... ........ 0,0-996,168 #7f0a0392 app:id/text_view}\n\nView Hierarchy:\n+>DecorView{id=-1, visibility=VISIBLE, width=1080, height=1920, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params={(0,0)(fillxfill) sim={adjust=resize} ty=BASE_APPLICATION wanim=0x10302fe\n fl=LAYOUT_IN_SCREEN LAYOUT_INSET_DECOR SPLIT_TOUCH HARDWARE_ACCELERATED DRAWS_SYSTEM_BAR_BACKGROUNDS\n pfl=NO_MOVE_ANIMATION FORCE_DRAW_STATUS_BAR_BACKGROUND FIT_INSETS_CONTROLLED\n bhv=DEFAULT\n fitSides=}, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, chil...
[debug] [W3C] Matched W3C error code 'unknown error' to UnknownError
[HTTP] <-- POST /session/f832bd3b-3a58-4794-ae71-9c1d0bab2867/element/82ea4f80-3cfc-4af5-b8a8-e24c55b165be/click 500 96 ms - 59373

@mykola-mokhnach
Copy link
Contributor

#824 should (probably) do the job

@mykola-mokhnach
Copy link
Contributor

#825 should enable scope argument support for data matchers

@mykola-mokhnach
Copy link
Contributor

Both PRs were published in driver version 2.12.0

@mykola-mokhnach
Copy link
Contributor

mykola-mokhnach commented Oct 15, 2022

basically setting the scope locator value is equal to providing inRoot matcher. If it is necessary to provide the parent AdapterView (e.g. the current page contains multiple ones) then find it first and use as context for the data matcher lookup (e.g. findElement(adapter view locator).findElement(data matcher))

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

3 participants