如何 select 浓缩咖啡中的列表视图?
How to select a listview in espresso?
我正在使用 espresso 进行测试,我在一个页面中有多个 AdapterView,例如,当我使用
时,id:R.id.list1,R.id.list2
onData(withMainValue("xx")).check(匹配(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.
如何 select 特定的列表视图并在其上尝试 onData ?
如果您有多个具有唯一 ID 的列表视图,您应该能够检查是否显示了其中一个列表
onView(withId(R.id.list1)).check(matches(isDisplayed()));
如果您想进入 AdapterView 内部,这将允许您单击列表视图中的一个元素
onData(anything()).inAdapterView(withId(R.id.list1)).atPosition(0).perform(click());
我正在使用 espresso 进行测试,我在一个页面中有多个 AdapterView,例如,当我使用
时,id:R.id.list1,R.id.list2onData(withMainValue("xx")).check(匹配(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.
如何 select 特定的列表视图并在其上尝试 onData ?
如果您有多个具有唯一 ID 的列表视图,您应该能够检查是否显示了其中一个列表
onView(withId(R.id.list1)).check(matches(isDisplayed()));
如果您想进入 AdapterView 内部,这将允许您单击列表视图中的一个元素
onData(anything()).inAdapterView(withId(R.id.list1)).atPosition(0).perform(click());