【问题标题】:Espresso: android.support.test.espresso.AmbiguousViewMatcherException for AdapterView浓缩咖啡:适配器视图的 android.support.test.espresso.AmbiguousViewMatcherException
【发布时间】:2015-07-15 07:17:05
【问题描述】:
我正在尝试使用 onData 运行 espresso 测试,对于其中只有一个 AdapterView 的视图,一切正常。但是,当屏幕显示一个嵌套了多个适配器视图的视图时,我得到:
android.support.test.espresso.AmbiguousViewMatcherException: 'is assignable from class: class android.widget.AdapterView' 匹配层次结构中的多个视图。
有没有办法指定onData 应该查看哪个适配器视图?
【问题讨论】:
标签:
android
android-espresso
android-adapterview
【解决方案1】:
为了回答问题,我们假设您的适配器视图之一是 ExpandableListView,另一个是 ListView,并且可以通过布局文件中的唯一 ID 轻松识别它们。
您需要做的就是使用 isDescendentOfA 匹配器来隔离您想要的 AdapterView,如下所示:
onData(...).
inAdapterView(allOf(
isAssignableFrom(AdapterView.class),
isDescendantOfA(withId(R.id.listView))))
但是,如果您的适配器视图没有不同的 id,只需查看它们的各种属性,您可能会发现唯一可识别的属性,您可以根据这些属性缩小选择范围。