Created
January 19, 2018 13:46
-
-
Save nmwilk/f42f9409b2a00f7c8e4c8e761810185b to your computer and use it in GitHub Desktop.
Use in Espresso tests to wait for the idle state.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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