In my functional tests while using espresso I want to click on a view inside a header in a ListView
.
According to https://code.google.com/p/android-test-kit/wiki/EspressoSamples#Matching_a_view_that_is_a_footer/header_in_a_ListView in order to have access to the header in my test I need to do this:
listView.addHeaderView(headerView, HEADER, true);
And access it like this:
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());
However, when I do that, my header will be clickable.
when I use:
listView.addHeaderView(headerView, HEADER, false);
espresso will not be able to access my view anymore.
How can I access the view from my test without making the header view clickable?
So far the best workaround I have found was to do the following:
Set the data on the
headerView
.Ignore click on the
headerView
.Hide the UI change on header click.