Using RecyclerViewActions on an extension of RecyclerView class

Viewed 307

I'm still learning Espresso's API and I currently need to tap on the first item in a class that is an extension of RecyclerView.

Here is the code I'm using to tap on the item:

onView(withId(R.id.[recyclerviewid])).perform(actionOnItemAtPosition(0, 
longClick()));

I was pointed to the recently added "RecyclerViewActions" but trying to tap on the item gives me the following error:

Caused by: java.lang.RuntimeException: Action will not be performed because 
the target view does not match one or more of the following constraints:
(is assignable from class: class android.support.v7.widget.RecyclerView and is 
displayed on the screen to the user)
Target view: "[Extension of RecyclerView class] {id=2131887687,..."

Looking at the object in say, uiautomatorviewer identifies it as a RecyclerView, however so I'm confused.

I'm considering trying to write a custom matcher for this but I'm not entirely sure where to start.

Anything helps, let me know if you need anymore info!

Update (5/17): Got started on a custom matcher for it but I have no idea what I'm doing or if I need to make another custom action for it as well.

Here's what I have so far after looking up BoundedMatchers although "getError()" can't be implemented since RecyclerViews don't have that method. Any feedback/suggestions will do:

@NonNull
public static Matcher<View> inRecyclerListView(final Matcher<Integer> listResourceId) {
    return new BoundedMatcher<View, RecyclerView>(RecyclerView.class) {


        @Override
        public void describeTo(Description description) {
            description.appendText("in list: " + listResourceId);
        }

        @Override
        protected boolean matchesSafely(final RecyclerView recyclerView) {
            return listResourceId.matches(listResourceId.getError().toString());
        }
    };
}
0 Answers
Related