> ## Content Index
> Fetch the complete content index at: https://codetraveler.io/llms.txt
> Use this file to discover other available public pages before exploring further.

# Xamarin.UITest: Is a ListView (or RefreshView) Refreshing?
- URL: https://codetraveler.io/2019/11/05/xamarin-uitest-determine-if-xamarin-forms-listview-is-refreshing/
- Published: 2019-11-05T19:24:00.000Z
- Updated: 2019-11-05T19:27:52.000Z
- Description: Automated UITesting has become critical for publishing mobile apps and almost every Xamarin.Forms app has ListView. But how can we determine if our ListView is refreshing? Let's find out!
- Author: Brandon Minnick
- Tags: Xamarin.UITest, Xamarin, Xamarin.Android, Xamarin.iOS, UITest, Automation, ListView

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

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

## Testing on Android

To interact with the ListView and the RefreshView on Android, we must use the [Invoke](https://docs.microsoft.com/dotnet/api/Xamarin.UITest.Queries.AppQuery.Invoke?view=xamarin-uitest-sdk?WT.mc%5Fid=listviewrefreshing-codetraveler-bramin&ref=codetraveler.io) method to access the [native Java Android API methods](https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html?ref=codetraveler.io#isRefreshing%28%29).

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

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

```

#### RefreshView

```csharp
 (bool)app.Query(x => x.Class("RefreshViewRenderer").Invoke("isRefreshing")).First();
```

## Testing on iOS

For iOS, we can check to see if the [UIRefreshControl](https://developer.apple.com/documentation/uikit/uirefreshcontrol?ref=codetraveler.io) is visible:

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

```

## Xamarin.UITest Sample

```csharp
//Xamarin.Forms.ListView
public bool IsListViewRefreshIndicatorDisplayed(Xamarin.UITest.IApp app)
{
    if (app is AndroidApp)
        return (bool)app.Query(x => x.Class("ListViewRenderer_SwipeRefreshLayoutWithFixedNestedScrolling").Invoke("isRefreshing")).First();

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

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

//Xamarin.Forms.RefreshView
public bool IsRefreshViewRefreshIndicatorDisplayed(Xamarin.UITest.IApp app)
{
    if (app is AndroidApp)
        return (bool)app.Query(x => x.Class("RefreshViewRenderer").Invoke("isRefreshing")).First();

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

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

```

## Sample App

Putting it all together, here is a sample app that implements this code: [https://github.com/brminnick/UITestSampleApp/](https://github.com/brminnick/UITestSampleApp/blob/master/Src/UITestSampleApp.UITests/Pages/ListPage.cs?ref=codetraveler.io)