Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Espresso test to verify that SwipeRefreshLayout is showing the refreshing indicator

I would like to create an Espresso test which verifies that SwipeRefreshLayout is showing the refreshing indicator. How can I do this?

like image 249
makovkastar Avatar asked May 02 '18 07:05

makovkastar


Video Answer


1 Answers

There is no standard Espresso matcher for this, but you can create a custom one:

object SwipeRefreshLayoutMatchers {
    @JvmStatic
    fun isRefreshing(): Matcher<View> {
        return object : BoundedMatcher<View, SwipeRefreshLayout>(
            SwipeRefreshLayout::class.java) {

            override fun describeTo(description: Description) {
                description.appendText("is refreshing")
            }

            override fun matchesSafely(view: SwipeRefreshLayout): Boolean {
                return view.isRefreshing
            }
        }
    }
}

And then you can use it like this:

onView(withId(R.id.swipe_refresh_layout)).check(matches(isRefreshing()))
like image 51
makovkastar Avatar answered Nov 15 '22 03:11

makovkastar