`ScrollToAction` doesn't work with `NestedScrollView`
Description
ScrollToAction currently throws an exception when used on a View which is a descendent of a NestedScrollView (the currently recommended scrollable view for vertical scrolling).
Steps to Reproduce
Write a test that attempts to scroll to a View that is contained within a NestedScrollView:
@Test
fun scrollToView() {
onView(withId(R.string.view_in_nested_scroll_view)).perform(scrollTo())
}
Expected Results
The scrollTo action scrolls to the view correctly.
Actual Results
Test fails with:
java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints:
(view has effective visibility <VISIBLE> and is descendant of a view matching (is assignable from class <class android.widget.ScrollView> or is assignable from class <class android.widget.HorizontalScrollView> or is assignable from class <class android.widget.ListView>))
Target view: "TextView{id=2131231165, res-name=time, visibility=VISIBLE, width=19, height=41, has-focus=false, has-focusable=false, 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=androidx.constraintlayout.widget.ConstraintLayout$LayoutParams@3bbb47e7, tag=null, root-is-layout-requested=false, has-input-connection=false, x=16.0, y=272.0, text=Time elapsed: 00:00, input-type=0, ime-target=false, has-links=false}"
at androidx.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:20)
at androidx.test.espresso.ViewInteraction.access$100(ViewInteraction.java:1)
at androidx.test.espresso.ViewInteraction$1.call(ViewInteraction.java:2)
at androidx.test.espresso.ViewInteraction$1.call(ViewInteraction.java:1)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at android.os.Handler.$$robo$$android_os_Handler$handleCallback(Handler.java:938)
at android.os.Handler.handleCallback(Handler.java)
at android.os.Handler.$$robo$$android_os_Handler$dispatchMessage(Handler.java:99)
at android.os.Handler.dispatchMessage(Handler.java)
at org.robolectric.shadows.ShadowPausedLooper$IdlingRunnable.run(ShadowPausedLooper.java:332)
at org.robolectric.shadows.ShadowPausedLooper.executeOnLooper(ShadowPausedLooper.java:366)
at org.robolectric.shadows.ShadowPausedLooper.idle(ShadowPausedLooper.java:92)
at org.robolectric.android.internal.LocalControlledLooper.drainMainThreadUntilIdle(LocalControlledLooper.java:17)
at androidx.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:1)
... 20 more
AndroidX Test and Android OS Versions
AndroidX Test 1.4.0 and any Android version.
A well documented work around for this is to create your own action to enable scrolling in NestedScrollView. An example of that can be found in this Stack Overflow post.
Is there an androidx.core:core-test artifact that could house this?
@TWiStErRob I could definitely be over simplifying, but I think NestedScrollView could be added to the anyOf assertion here to add support to the existing ScrollToAction.
That would be best, I agree. I have a feeling they can't just add the class reference, because that would mean pulling in a dependency that is not really used. Luckily that method has a String overload, next to the Class one, so there's hope.
This should be fixed in espresso 3.5.0
Thank you, it is working like expected.
(needed to fix https://github.com/android/android-test/issues/1589 first)