Automated UI testing has become critical for publishing 5-star apps and many Xamarin.Forms apps display data in a ListView. But how can our UI tests determine if our ListView is refreshing? Let's find out!

We'll need to access the platform-specific APIs to check if the ListView is refreshing. Thus, we'll be using different code to test Android vs iOS.

Testing on Android

To interact with the ListView on Android, we must use the Invoke method to access the  native Java Android API methods.

On Android, we can check the value returned from SwipeRefreshLayout.isRefreshing() like so:

(bool)(app.Query(x => x.Class("ListViewRenderer_SwipeRefreshLayoutWithFixedNestedScrolling").Invoke("isRefreshing")).First();

Testing on iOS

For iOS, we can check to see if the UIRefreshControl is visible:

app.Query(x => x.Class("UIRefreshControl")).Any()

Xamarin.UITest Sample

public bool IsRefreshIndicatorDisplayed(Xamarin.UITest.IApp app)
    if (app is AndroidApp)
        return (bool)(app.Query(x => x.Class("ListViewRenderer_SwipeRefreshLayoutWithFixedNestedScrolling")?.Invoke("isRefreshing"))?.FirstOrDefault() ?? false);

    if (app is iOSApp)
        return app.Query(x => x.Class("UIRefreshControl"))?.Any() ?? false;

    throw new NotSupportedException("Xamarin.UITest only supports Android and iOS");

Sample App

Putting it all together, here is a sample app that implements