Skip to content

Instantly share code, notes, and snippets.

@realdadfish
Created October 29, 2014 07:44
Show Gist options
  • Save realdadfish/2622caecc1b2d498cd1a to your computer and use it in GitHub Desktop.
Save realdadfish/2622caecc1b2d498cd1a to your computer and use it in GitHub Desktop.
Workaround for Espresso / Android Test Kit to "support" RecyclerView matching.
public class ViewMatchers
{
@SuppressWarnings("unchecked")
public static Matcher<View> withRecyclerView(@IdRes int viewId)
{
return allOf(isAssignableFrom(RecyclerView.class), withId(viewId));
}
@SuppressWarnings("unchecked")
public static ViewInteraction onRecyclerItemView(@IdRes int identifyingView, Matcher<View> identifyingMatcher, Matcher<View> childMatcher)
{
Matcher<View> itemView = allOf(withParent(withRecyclerView(R.id.start_grid)),
withChild(allOf(withId(identifyingView), identifyingMatcher)));
return Espresso.onView(allOf(isDescendantOfA(itemView), childMatcher));
}
}
@wischweh
Copy link

which R. do i have to import to get the start_grid?

@Daard
Copy link

Daard commented Mar 14, 2016

Probably, recycler_view_id.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment