选择未显示的模糊视图

时间:2014-12-18 23:44:10

标签: android android-espresso

在我的espresso测试中,我想通过id选择一个视图。视图低于折叠,所以我需要scrollTo()它。此视图与另一个隐藏的视图共享其id。

这会产生不明确的视图错误:

onView(withId(textViewId)).perform(scrollTo(), myAction);

所以:

onView(allOf(ViewMatchers.isEnabled(), withId(textViewId)))
    .perform(scrollTo(), myAction);

这不会给出匹配的视图异常:

onView(allOf(ViewMatchers.isDisplayed(), withId(textViewId)))
    .perform(scrollTo(), myAction);

如何唯一地选择我想要的视图?

1 个答案:

答案 0 :(得分:1)

我通过识别一个独特的祖先视图解决了这个问题。

onView(allOf(isDescendantOfA(withId(R.id.someParent)), withId(textViewId)))
    .perform(scrollTo(), myAction);