Using RecyclerViewActions to Extend RecyclerView Class

I am still learning the espresso API and right now I need to use the first item in the class which is an extension of the RecyclerView.

Here's the code I'm using to click on an element:

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

      

I pointed to the newly added "RecyclerViewActions" but trying to click 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 an object, say the uiautomatorviewer identifies it as a RecyclerView, however I am confused.

I'm thinking about trying to write special matches for this, but I'm not really sure where to start.

Anything help, let me know if you need more information!

Update (5/17): I'll start with a custom match, but I have no idea what I am doing or if I need to do another custom action for it.

Here is what I have so far after looking for BoundedMatchers, although "getError ()" cannot be implemented as RecyclerViews do not have this 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());
        }
    };
}

      

+3


source to share





All Articles