Inkognito
Inkognito

Reputation: 197

Check text on position in recycler

I have method, where i click on position my recyclerView:

Espresso.onView(ViewMatchers.withId(R.id.recyclerView))
        .perform(RecyclerViewActions.actionOnItemAtPosition<CurrencySelectorItemHolder>(1, ViewActions.click()))

But how i can just check on position my text for example?

Upvotes: 5

Views: 1726

Answers (1)

Abdennacer Lachiheb
Abdennacer Lachiheb

Reputation: 4888

Change "whatever" to the text you want :

Espresso.onView(withId(R.id.recyclerView))
      .perform(RecyclerViewActions.actionOnItem(
                hasDescendant(withText("whatever")), click()));

UPDATE : this code for checking text by position :

onView(withRecyclerView(R.id.recyclerView).atPosition(3))
    .check(matches(hasDescendant(withText("whatever"))));

public static RecyclerViewMatcher withRecyclerView(final int recyclerViewId) {
    return new RecyclerViewMatcher(recyclerViewId);
}

RecyclerViewMatcher.java

Upvotes: 6

Related Questions