Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ambiguous results from Espresso on a fairly basic test

We have a page that in a sense acts like email. So we have a Recyclerview with a bunch of TextViews, one of them being a large TextView containing all the email content.

So we are just trying to test that the entire text of the email is loaded and displayed (we append a special string at the end and we are going to test that is shows up).

Espresso.onView( Matchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withId(R.id.email_content)) )
            .perform(ViewActions.scrollTo(), ViewActions.swipeUp());

When this is ran we get this error:

Caused by: android.support.test.espresso.PerformException: Error performing 'click (after 3 attempts)' on view 'unknown'.
at android.support.test.espresso.PerformException$Builder.build(PerformException.java:83)
at android.support.test.espresso.action.MotionEvents.sendDown(MotionEvents.java:111)
at android.support.test.espresso.action.Swipe.sendLinearSwipe(Swipe.java:88)
at android.support.test.espresso.action.Swipe.access$100(Swipe.java:31)
at android.support.test.espresso.action.Swipe$1.sendSwipe(Swipe.java:38)
at android.support.test.espresso.action.GeneralSwipeAction.perform(GeneralSwipeAction.java:70)

So when we change it to this:

    Espresso.onView( Matchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withId(R.id.email_content)) )
            .perform(ViewActions.swipeUp());

We get this error:

Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints: 
at least 90 percent of the view's area is displayed to the user.
Target view: "AppCompatTextView{id=2131558822, res-name=email_content, visibility=VISIBLE, width=1048, height=1513896, 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, root-is-layout-requested=false, has-input-connection=false, x=16.0, y=175.0, text=

Why in the 1st case it says it couldn't scroll the view and in the 2nd case it says it isn't fully visible enough?

like image 474
arinte Avatar asked Sep 06 '25 03:09

arinte


1 Answers

ViewActions.scrollTo() can not be used with RecyclerView because scrollTo requires to work only with objects that inherited from ScrollView. To scroll to necessary item in RecyclerView you should write your own ViewAction. You can take a look how to make this here see method scrollToPosition

like image 192
Vyacheslav Pedak Avatar answered Sep 07 '25 19:09

Vyacheslav Pedak