Check if a ListView has an specific a number of items, and scroll to last one with Espresso

android, android-espresso, integration-testing

Solution

Even though @denys answer seemed to be correct at first glance, it looks like it works only on certain cases (as suggested by Espresso author). The proper way to scroll to an specific item is as replied here on android-test-kit-discuss forum, and reproduced below:

onData(instanceOf(Item.class))
            .inAdapterView(allOf(withId(android.R.id.list), isDisplayed()))
            .atPosition(9)
            .check(matches(isDisplayed()));

Problem

I'm trying to implement this using Google's Espresso, however I'm not finding any `ViewAssertion` or `ViewAction` that'd allow me to do this. I'm not sure if these can be done using bundled in matchers or should I write my own. Thanks!

Original source