gpt4 book ai didi

android - Espresso : android. support.test.espresso.AmbiguousViewMatcherException for AdapterView

转载 作者:行者123 更新时间:2023-11-29 01:30:36 27 4
gpt4 key购买 nike

我正在尝试使用 onData 运行 espresso 测试,对于其中只有一个 AdapterView 的 View ,一切正常。但是,当屏幕显示其中嵌套了多个适配器 View 的 View 时,我得到:

android.support.test.espresso.AmbiguousViewMatcherException: 'is assignable from class: class android.widget.AdapterView' matches multiple views in the hierarchy.

有什么方法可以指定 onData 应该查看哪个适配器 View ?

最佳答案

为了得到答案,我们假设您的一个适配器 View 是 ExpandableListView,另一个是 ListView,并且可以通过布局文件中的唯一 ID 轻松识别它们。

您需要做的就是使用 isDescendentOfA 匹配器来隔离您想要的 AdapterView,如下所示:

onData(...).
inAdapterView(allOf(
isAssignableFrom(AdapterView.class),
isDescendantOfA(withId(R.id.listView))))

但是,如果您的适配器 View 没有不同的 ID,只需查看它们的各种属性,您可能会发现唯一可识别的属性,您可以根据这些属性缩小选择范围。

关于android - Espresso : android. support.test.espresso.AmbiguousViewMatcherException for AdapterView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31423831/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com