xamarinxamarin.uitest

Xamarin.UITest RecyclerView wait for items to load


I am trying to write an Xamarin.UITest for my Android project. My app has a "download" UIButton, that when pressed, downloads data and then populates a RecyclerView. Then when a "clear" UIButton is pressed, the RecyclerView is cleared. This is what I tried so far:

app.Tap(c => c.Marked("download_btn"));
app.WaitForElement(x => x.Marked("recycler_item"), "Timed out waiting for items to load", TimeSpan.FromSeconds(5));
app.Tap(c => c.Marked("clear_btn"));

The app.WaitForElement part never finds the items in the RecyclerView, even when they are there. I want to test that there is at least 1 item in the RecyclerView after I tap the download button.


Solution

  • I figured out how to wait for the RecyclerView to load. You can wait for a view that is inside the layout of item itself, such as a TextView:

    app.WaitForElement(x => x.Marked("name_textView"), "Timed out waiting for items to load", TimeSpan.FromSeconds(3));