0

I am running an Espresso test simply to test the click of a view in a RecyclerView and the text within the view of the RecyclerView.

The test passes on my Genymotion emulator, fails on my device (Google Nexus 6), and I cannot figure out why:

@RunWith(AndroidJUnit4.class)
public class EspressoTest {


    @Rule
    public ActivityTestRule<MainActivity> firstRule = new ActivityTestRule<>(MainActivity.class);


    @Test
    public void testRecyclerViewClick() {
        Espresso.onView(ViewMatchers.withId(R.id.recycler_view_ingredients)).perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));
    }

    //TODO: This test is not passing on my device, but it is passing on an emulator. I am not sure why, but have read about idling resources. Can you confirm how to handle?
    @Test
    public void testRecyclerViewText(){
        Espresso.onView(ViewMatchers.withId(R.id.recycler_view_ingredients)).perform(RecyclerViewActions.scrollToPosition(0));
        Espresso.onView(withText("Nutella Pie")).check(matches(isDisplayed()));
    }

}
tccpg288
  • 3,242
  • 5
  • 35
  • 80
  • 1
    the example which I've previously provided was actually tested & screen-recorded on a Nexus 6, and that answer had never been accepted, despite it was correct ... while that `onView(withText("Nutella Pie"))` might fail to match, possibly because you do not use the `RecyclerViewMatcher` (which I've suggested for a good reason). Genemotion might report a false positive ...does the regular emulator also report the test as "passed"? I'd simply match it into a variable and then `assert` it to be `!= null`. – Martin Zeitler Aug 18 '18 at 02:37
  • Possible duplicate of [How to Test RecyclerView ViewHolder Text with Espresso](https://stackoverflow.com/questions/51678563/how-to-test-recyclerview-viewholder-text-with-espresso) – Martin Zeitler Aug 18 '18 at 02:48

0 Answers0