[英]espresso onData matches multiple views in the hierarchy?
我正在使用espresso测试一个应用程序。 这个应用程序有2个ListView,espresso onData函数找到两个ListView,但是它们具有不同的ID。
码:
onData(withId(R.id.order_jijia_listview)).perform(ViewActions.click());
结果:
ListView{id=2131493579, res-name=order_jijia_listview, visibility=VISIBLE, width=768,
height=659, has-focus=false, has-focusable=true, has-window-focus=true,
is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true,
is-layout-requested=false, is-selected=false, root-is-layout-requested=false,
has-input-connection=false, x=0.0, y=345.0, child-count=7} ****MATCHES****
ListView{id=2131493586, res-name=order_jijia_pop_listview, visibility=VISIBLE, width=0,
height=0, has-focus=false, has-focusable=false, has-window-focus=true,
is-clickable=true, is-enabled=true, is-focused=false, is-focusable=false,
is-layout-requested=true, is-selected=false, root-is-layout-requested=false,
has-input-connection=false, x=0.0, y=0.0, child-count=0}
第二个ListView未标记为****MATCHES****
,因此问题不存在。
您应仅将onData
用于ListView元素,而不应用于ListView
本身。 要找到ListView,您需要使用onView
:
onView(withId(R.id.order_jijia_listview)).perform(ViewActions.click());
您想实现什么? 单击列表元素? 因此,您需要将onData
与复杂的匹配器配合使用:
onData(allOf(is(instanceOf(String.class)), is("Americano"))).perform(click());
您可以在官方espresso教程中阅读有关onData
和onView
更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.