Espresso - 使用包含其他网格视图的视图寻呼机内部的网格视图

时间:2016-06-10 17:05:47

标签: android android-espresso

我正在尝试从位于视图寻呼机中的网格视图中选择一个项目。

视图寻呼机中的不同页面包含相同的网格视图(但内容不同)。

有办法以某种方式解决这个问题吗?

我有以下逻辑:

onData(new BaseMatcher<String>() {
    @Override
    public void describeTo(Description description) {
        // what?
        description.appendText("Matches A");
    }

    @Override
    public boolean matches(Object item) {
        return item instanceof String && ((String) item).equals("A");
    }
}).inAdapterView(allOf(withId(R.id.grid_view))).perform(click());

我希望开始使用/工作(基础匹配器需要更新匹配方法,但我可以继续处理...)。

然而,由于以下原因,通话失败:

android.support.test.espresso.AmbiguousViewMatcherException: '(with id: com.zachproject.espresso:id/grid_view)' matches multiple views in the hierarchy.
Problem views are marked with '****MATCHES****' below.

这是有道理的,因为找到了多个grid_view id(在视图寻呼机中每页一个)。

任何使这项工作成功的想法?

谢谢, 扎克

1 个答案:

答案 0 :(得分:1)

如果您将isDisplayed()添加到适配器匹配器,它只会匹配屏幕上显示的AdapterView,在大多数情况下,它将是当前页面上的AdapterView

allOf(withId(R.id.grid_view), isDisplayed())

相关问题