我正在使用espresso进行测试,我在一个页面中有多个AdapterView,例如,当我使用
时,id为:R.id.list1,R.id.list2昂达(withMainValue(" XX&#34))。检查(匹配(isDisplayed()))
public static Matcher<Object> withMainValue(final String value) {
return new BoundedMatcher<Object,
GuessYouLikeGoodItem.DataEntity>(GuessYouLikeGoodItem.DataEntity.class) {
@Override public void describeTo(Description description) {
description.appendText("has value " + value);
}
@Override public boolean matchesSafely(
GuessYouLikeGoodItem.DataEntity item) {
return item.store_name.contains(value);
}
};
}
,
Espresso报道:
android.support.test.espresso.AmbiguousViewMatcherException: 'is assignable from class: class android.widget.AdapterView' matches multiple views in the hierarchy.
Problem views are marked with '****MATCHES****' below.
如何选择特定的列表视图并尝试使用onData?
答案 0 :(得分:5)
如果您有多个listview具有唯一ID,您应该能够检查是否显示了一个列表
onView(withId(R.id.list1)).check(matches(isDisplayed()));
如果你想进入AdapterView,你可以点击listview里面的元素
onData(anything()).inAdapterView(withId(R.id.list1)).atPosition(0).perform(click());