在使用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将无法再访问我的视图。
如何在不使标题视图可点击的情况下从我的测试中访问视图?
答案 0 :(得分:0)
到目前为止,我发现最好的解决方法是执行以下操作:
在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"