AgtLucas / android-test-kit

Automatically exported from code.google.com/p/android-test-kit
0 stars 0 forks source link

using onData in RecyclerView #156

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What is the recommended way to use onData in a recyclerView ?
It does not seem to be supported. Are than any plans to include support?

Thanks.

Original issue reported on code.google.com by eng.prud...@gmail.com on 26 May 2015 at 2:19

GoogleCodeExporter commented 9 years ago
Have you tried any of these - 
http://developer.android.com/reference/android/support/test/espresso/contrib/Rec
yclerViewActions.html ?

Original comment by KAM...@gmail.com on 27 May 2015 at 1:34

GoogleCodeExporter commented 9 years ago
RecyclerViewActions only supports performing actions on RecyclerView. 
However it doensn't support check with view assertions the state of a recycler 
view child view.

Original comment by eng.prud...@gmail.com on 27 May 2015 at 9:50

GoogleCodeExporter commented 9 years ago
That WAI. You should use RecylcerViewActions to interact with RV. RV is not 
really compatible with AdapterViews and the way we actually obtain the the View 
for a given piece of data. Here is an example how you should use the API:

    onView(withId(rvLayoutId)).perform(scrollTo(hasDescendant(withText(ITEM_128))));
    onView(withItemText(ITEM_128)).check(matches(isDisplayed()));

So instead of using onData...check(..) you first scroll the View into ViewPort 
using the scrollTo(...) Action and then you can perform a ViewAssertion like 
you usually do with espresso. 

Original comment by slinz...@google.com on 8 Jun 2015 at 3:45

GoogleCodeExporter commented 9 years ago
Imagine the following layout:

RecyclerView
 -> View 
    -> Other views
    -> Button with text "Ok"
-> View 
    -> Other views
    -> Button with text "Ok"
 -> View 
    -> Other views
    -> Button with text "Ok"
-> View 
    -> Other views
    -> Button with text "Ok"

So I want to assert if the view at index 1 has a button with the text "Ok". 
Using your approach it would be basically an ambiguous query because the same 
text would appear multiple times.

Moreover scrollTo cannot guarantee that the button is actually visible, because 
the child view  of the recycler view could occupy more space than the screen.

Original comment by eng.prud...@gmail.com on 8 Jun 2015 at 5:53