android-test icon indicating copy to clipboard operation
android-test copied to clipboard

`ScrollToAction` doesn't work with `NestedScrollView`

Open seadowg opened this issue 4 years ago • 4 comments

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.

seadowg avatar Jan 11 '22 16:01 seadowg

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.

seadowg avatar Jan 11 '22 16:01 seadowg

Is there an androidx.core:core-test artifact that could house this?

TWiStErRob avatar Jan 14 '22 19:01 TWiStErRob

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

seadowg avatar Jan 17 '22 10:01 seadowg

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.

TWiStErRob avatar Jan 17 '22 18:01 TWiStErRob

This should be fixed in espresso 3.5.0

brettchabot avatar Dec 05 '22 18:12 brettchabot

Thank you, it is working like expected.

(needed to fix https://github.com/android/android-test/issues/1589 first)

TZanke avatar Dec 07 '22 12:12 TZanke