Skip to content

Instantly share code, notes, and snippets.

@nmwilk
Created January 19, 2018 13:46
Show Gist options
  • Save nmwilk/f42f9409b2a00f7c8e4c8e761810185b to your computer and use it in GitHub Desktop.
Save nmwilk/f42f9409b2a00f7c8e4c8e761810185b to your computer and use it in GitHub Desktop.
Use in Espresso tests to wait for the idle state.
import android.support.test.InstrumentationRegistry
import java.util.concurrent.CountDownLatch
fun waitForIdle(errorMessage: String) {
val countDownLatch = CountDownLatch(1)
InstrumentationRegistry.getInstrumentation().waitForIdle { countDownLatch.countDown() }
try {
countDownLatch.await()
} catch (e: InterruptedException) {
throw RuntimeException(errorMessage, e)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment