在Espresso测试案例的“回收者”视图中,某项的单击操作,我遇到以下错误:
android.support.test.espresso.PerformException: Error performing 'performing ViewAction: single click on item matching: view holder with title: storeName1' on view 'with id: proto.inventa.cct.com.inventaapp:id/mainRecyclerView123'.
at android.support.test.espresso.PerformException$Builder.build(PerformException.java:84)
at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:81)
at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:52)
at android.support.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:312)
at android.support.test.espresso.ViewInteraction.desugaredPerform(ViewInteraction.java:167)
at android.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:110)
Matcher<RecyclerView.ViewHolder> matcher = withTitle("storeName1");
onView((withId(R.id.mainRecyclerView123))).perform(actionOnHolderItem(matcher, click()));
public static Matcher<RecyclerView.ViewHolder> withTitle(final String title)
{
return new BoundedMatcher<RecyclerView.ViewHolder, StoresListAdapter.ViewHolder>(StoresListAdapter.ViewHolder.class)
{
@Override
protected boolean matchesSafely(StoresListAdapter.ViewHolder item)
{
return item.mtvStoreName.getText().toString().equalsIgnoreCase(title);
}
@Override
public void describeTo(Description description)
{
description.appendText("view holder with title: "+ title);
}
};
}