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()));
}
}