Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Outline for an Espresso test that interacts with BottomSheets in a reliable way
@Test
fun clickButtonInsideExpandedBottomSheet() {
val sheetBehavior = activity.getBottomSheetBehavior()
val expandedSheetIdlingResource = BottomSheetStateResource(sheetBehavior, STATE_EXPANDED)
val settledSheetIdlingResource = BottomSheetSettledResource(sheetBehavior)
// Wait for settled state
withBottomSheetResource(settledSheetIdlingResource) {
// Use BottomSheetSetStateAction to expand the Bottom Sheet
}
// Wait for expanded state
withBottomSheetResource(expandedSheetIdlingResource) {
// Click on button inside Bottom Sheet content
}
// Assert that button had the intended effect
}
private fun withBottomSheetResource(
sheetIdlingResource: IdlingResource,
actionsAndAssertions: () -> Unit
) {
with(sheetIdlingResource) {
idlingRegistry.register(this)
try {
actionsAndAssertions.invoke()
} finally {
idlingRegistry.unregister(this)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment