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
One simple way to check for a View or its subclass like a Button is to use method getVisibility from View class.
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!")))
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With