Reputation: 12467
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
Upvotes: 8
Views: 8150
Reputation: 1525
There is also the following:
InstrumentationRegistry.getInstrumentation().waitForIdle {
}
which run the code inside lambda after it is idle.
Upvotes: 1
Reputation: 2019
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()
Upvotes: 8