Skip to content Skip to sidebar Skip to footer

Espresso - Asserting A Textview With Async Loaded Data

I'm writing a UI test with Google Espresso for Android and I'm stuck on how to assert a TextView text, which content is asynchronously loaded from a web service. My current code is

Solution 1:

You can handle this case by registering an IdlingResource for your web service with Espresso. Take a look at this write-up: https://developer.android.com/training/testing/espresso/idling-resource.html

Most likely, you'll want to use CountingIdlingResource (which uses a simple counter to track when something is idle). This sample test demonstrates how this can be done.

Solution 2:

If you're not bothered with using UiAutomator with Espresso, you could do something like this in your step 4.

UiObject object = mDevice.findObject(new UiSelector().resourceId(packageName + ":id/" + "review_box"));
object.waitForExists(5000);

https://developer.android.com/reference/android/support/test/uiautomator/UiObject.html#waitForExists(long)

Post a Comment for "Espresso - Asserting A Textview With Async Loaded Data"