her*_*rtD 4 testing android listview android-espresso
我正在使用espresso进行测试,并且在使用一个页面时有多个AdapterView,例如,使用时ID为R.id.list1,R.id.list2
onData(withMainValue(“ xx”))。check(matches(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);
}
};
}
,
Run Code Online (Sandbox Code Playgroud)
浓缩咖啡报告:
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.
Run Code Online (Sandbox Code Playgroud)
如何选择特定的listview并尝试onData?
如果您有多个具有唯一ID的列表视图,则应该能够检查是否显示了列表之一
onView(withId(R.id.list1)).check(matches(isDisplayed()));
Run Code Online (Sandbox Code Playgroud)
如果要进入AdapterView,可以单击listview中的元素
onData(anything()).inAdapterView(withId(R.id.list1)).atPosition(0).perform(click());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4049 次 |
| 最近记录: |