android-test icon indicating copy to clipboard operation
android-test copied to clipboard

[FR] Assert an item is present or not in RecyclerView.

Open ibzib opened this issue 3 years ago • 0 comments

Description

I'm looking for an easy way to assert whether an element is present or not in RecyclerView, without having to scroll (the element might or might not be currently on screen). I found a workaround was to assert that clicking the item throws an exception:

Assert.assertThrows(PerformException.class, () -> onView(recyclerView)
        .perform(RecyclerViewActions.actionOnItem(matcher, click())));

But I'd prefer to write something like the following instead, which is more precise and direct:

onView(recyclerView).perform(RecyclerViewActions.hasItemMatching(matcher)));

See also this Medium post where the author implements a RecyclerViewAssertions class along these lines.

ibzib avatar Sep 02 '22 18:09 ibzib