onView(allOf(withText(activityUnderTest), withParent(withId(R.id.llh_root_record_activity_3_item)))).check(matches(anything())) ;
在上面的代码片段withParent
匹配器失败,因为给定的视图ID不是直接父级而是祖父级。
它可以按照以下方式处理,但很想知道这个技巧,特别是当你不想指定下面代码中使用的凌乱的层次结构时。
onView(allOf(withText(activityUnderTest), withParent(withParent(withParent(withId(R.id.llh_root_record_activity_3_item)))))).check(matches(anything())) ;
答案 0 :(得分:22)
isDescendantOfA就是您所需要的。
实际上,它不适用于大父母。
请检查espresso cheat sheet
onView(allOf(withText(activityUnderTest), isDescendantOfA(withId(R.id.llh_root_record_activity_3_item))))
.check(matches(isDisplayed()));