-1

我一直在寻找在咖啡样品,但他们只用下面的方法如何找到孩子在咖啡一些项目位置recyclerview

actionOnItemAtPosition 

在大多数情况下,给予直接的方法,在一些位置上进行点击,我们会需要在某个位置点击多个子项目中的一个。像一个TextView,ImageView和复选框。

如果我的Recyclerview有50个项目,我没有看到任何简单的方法到达位置25的复选框。除了定义我自己的ViewAction实现,任何人都可以有任何简单的解决方案。

回答

0

你可以这样创建自己的withIndex匹配:

public static Matcher<View> withIndex(final Matcher<View> matcher, final int index) { 
    return new TypeSafeMatcher<View>() { 
     int currentIndex = 0; 

     @Override 
     public void describeTo(Description description) { 
      description.appendText("with index: "); 
      description.appendValue(index); 
      matcher.describeTo(description); 
     } 

     @Override 
     public boolean matchesSafely(View view) { 
      return matcher.matches(view) && currentIndex++ == index; 
     } 
    }; 
} 

使用例如

int indexToSelect = 4; 
onView(allOf(withIndex(withId(R.id.textViewToSelect), indexToSelect), isDescendantOfA(withId(R.id.customRecyclerView)))).perform(click());