Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Espresso - how to wait for idle without an assertion/view interaction?

I would like to simply block the instrumentation (test) thread until Espresso is idle.

fun test(){
    // do some stuff
    Espresso.waitForIdle()
    // do some more stuff once Espresso reports that the application is idle
}

What's the best way to do this?

note: Espresso.waitForIdle() is a method I made up

like image 635
ZakTaccardi Avatar asked Nov 01 '18 17:11

ZakTaccardi


People also ask

How do you check espresso visibility?

One simple way to check for a View or its subclass like a Button is to use method getVisibility from View class.

How do you assert espresso?

The most used assertion is the matches() assertion. It uses a ViewMatcher object to assert the state of the currently selected view. onView(...). check(matches(withText("Hello!")))


1 Answers

You can use InstrumentationRegistry.getInstrumentation().waitForIdleSync(). https://developer.android.com/reference/android/app/Instrumentation.html#waitForIdleSync()

There is also Espresso.onIdle(), but the documentation warns Only call this method for tests that do not interact with any UI elements, but require Espresso's main thread synchronisation! https://developer.android.com/reference/android/support/test/espresso/Espresso.html#onIdle()

like image 89
chessdork Avatar answered Oct 10 '22 21:10

chessdork