Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Espresso - scrolling to a non-list View item

Is there a general approach for scrolling to non-list View items that are not yet visible on the screen?

Without any precautions, Espresso will indicate that "No Views in hierarchy found matching with id .....

I found this answer ... is this the best approach?

onView( withId( R.id.button)).perform( scrollTo(), click());
like image 560
tm1701 Avatar asked Aug 20 '14 17:08

tm1701


1 Answers

According to the scrollTo JavaDoc, to use the code you specified ( onView( withId( R.id.button)).perform( scrollTo(), click()); ), the preconditions are: "must be a descendant of ScrollView" and "must have visibility set to View.VISIBLE". If that is the case, then that will work just fine.

If it is in an AdapterView, then you should use onData instead. In some cases, you may have to implement the AdapterViewProtocol, if your AdapterView is not well behaved.

If it is neither in an AdapterView nor a child of a ScrollView, then you would have to implement a custom ViewAction.

like image 156
yogurtearl Avatar answered Oct 04 '22 01:10

yogurtearl