我试图单击RecyclerView内的可绘制对象。 脚步。 1.向左滑动以打开可绘制/删除图标。 2.单击可绘制对象
我可以在recyclerView项目上滑动,但是我不知道如何单击垃圾箱。
这是我向左滑动的方法。
public void swipeLeftToDelete(int position) {
ViewInteraction recyclerView5 = Espresso.onView(
allOf(ViewMatchers.withId(R.id.myRecyclerView),
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
position)));
recyclerView5.perform(actionOnItemAtPosition(position, swipeLeft()));
}
private static Matcher<View> childAtPosition(
final Matcher<View> parentMatcher, final int position) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("Child at position " + position + " in parent ");
parentMatcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
ViewParent parent = view.getParent();
return parent instanceof ViewGroup && parentMatcher.matches(parent)
&& view.equals(((ViewGroup) parent).getChildAt(position));
}
};
}