【问题标题】:Espresso List header non-clickable浓缩咖啡列表标题不可点击
【发布时间】:2015-06-26 13:22:42
【问题描述】:

在我使用 espresso 的功能测试中,我想单击 ListView 中标题内的视图。

根据https://code.google.com/p/android-test-kit/wiki/EspressoSamples#Matching_a_view_that_is_a_footer/header_in_a_ListView,为了在我的测试中访问标头,我需要这样做:

listView.addHeaderView(headerView, HEADER, true);

然后像这样访问它:

public static Matcher<Object> isHeader() {
    return allOf(is(instanceOf(String.class)), Matchers.<Object>is(TestUtil.HEADER));
}

&

onData(ViewMatchers.isHeader())
        .inAdapterView(allOf(withId(R.id.list_view), isDisplayed()))
        .onChildView(withId(R.id.view_to_click))
        .check(matches(isDisplayed()))
        .perform(click());

但是,当我这样做时,我的标题将是可点击的。

当我使用时:

listView.addHeaderView(headerView, HEADER, false);

espresso 将无法再访问我的视图。

如何在不使标题视图可点击的情况下访问我的测试中的视图?

【问题讨论】:

    标签: android listview android-listview android-espresso


    【解决方案1】:

    到目前为止,我发现的最佳解决方法是执行以下操作:

    headerView上设置数据。

    listView.addHeaderView(header, TestUtil.HEADER, true);
    

    忽略点击headerView

    @Override
    public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) {
        // Ignore the headerView.
        if (position == 0) {
            return;
        }
        ...
    }
    

    隐藏标题点击时的 UI 更改。

    android:listSelector="@android:color/transparent"
    

    【讨论】:

      猜你喜欢
      • 2015-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多