Skip to content

Instantly share code, notes, and snippets.

@Sushisugre
Last active August 29, 2015 14:19
Show Gist options
  • Save Sushisugre/989eff328ad5fa4841b7 to your computer and use it in GitHub Desktop.
Save Sushisugre/989eff328ad5fa4841b7 to your computer and use it in GitHub Desktop.
Works with child view inside of RecyclerView item using espresso, inspired by https://gist.github.com/tommyd3mdi/2622caecc1b2d498cd1a
public static Matcher<View> withRecyclerViewId(int recyclerViewId) {
return allOf(isAssignableFrom(RecyclerView.class), withId(recyclerViewId));
}
/**
* Returns a matcher for an item (cell) in recycler view.
*
* @param recyclerViewId
* @param childViewMatcher
* @return
*/
public static Matcher<View> withRecyclerItemView(
int recyclerViewId,
Matcher<View> childViewMatcher) {
return allOf(withParent(withRecyclerViewId(recyclerViewId)),
(childViewMatcher));
}
/**
* Get the view interaction of the child view inside of a RecyclerView item
*
* @param recyclerViewId resources Id of target RecyclerView
* @param ItemIdentifier Matcher for the desired item (cell)
* @param childViewMatcher Matcher for the child view in the item
* @return
*
*/
public static ViewInteraction onRecyclerItemView(
int recyclerViewId,
Matcher<View> ItemIdentifier,
Matcher<View> childViewMatcher) {
Matcher<View> itemView = withRecyclerItemView(recyclerViewId, ItemIdentifier);
return Espresso.onView(allOf(isDescendantOfA(itemView), childViewMatcher));
}
@Sushisugre
Copy link
Author

Unlike working with DataInteractions, this workaround doesn't load the view(data) in adapter that is not yet visible.

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