如何在浓缩咖啡中选择列表视图?

时间:2016-06-15 04:01:28

标签: android listview testing android-espresso

我正在使用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?

1 个答案:

答案 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());