appium-espresso-driver icon indicating copy to clipboard operation
appium-espresso-driver copied to clipboard

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

Open Scrubles opened this issue 3 years ago • 13 comments

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.

Scrubles avatar Oct 05 '22 20:10 Scrubles

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

KazuCocoa avatar Oct 06 '22 07:10 KazuCocoa

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

Scrubles avatar Oct 06 '22 15:10 Scrubles

Have you tried to use -android viewmatcher locators?

mykola-mokhnach avatar Oct 06 '22 16:10 mykola-mokhnach

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

KazuCocoa avatar Oct 06 '22 16:10 KazuCocoa

After v2.11.0 is is possible to provide root matchers to -android viewmatcher locators. See https://github.com/appium/appium-espresso-driver/pull/822

mykola-mokhnach avatar Oct 08 '22 07:10 mykola-mokhnach

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?

Scrubles avatar Oct 13 '22 16:10 Scrubles

Could you provide the full stack trace?

mykola-mokhnach avatar Oct 13 '22 16:10 mykola-mokhnach

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

mykola-mokhnach avatar Oct 13 '22 16:10 mykola-mokhnach

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

Scrubles avatar Oct 13 '22 16:10 Scrubles

https://github.com/appium/appium-espresso-driver/pull/824 should (probably) do the job

mykola-mokhnach avatar Oct 13 '22 17:10 mykola-mokhnach

https://github.com/appium/appium-espresso-driver/pull/825 should enable scope argument support for data matchers

mykola-mokhnach avatar Oct 14 '22 13:10 mykola-mokhnach

Both PRs were published in driver version 2.12.0

mykola-mokhnach avatar Oct 15 '22 19:10 mykola-mokhnach

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

mykola-mokhnach avatar Oct 15 '22 19:10 mykola-mokhnach