Skip to content

Instantly share code, notes, and snippets.

Last active August 3, 2023 19:41
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Outline for an Espresso test that interacts with BottomSheets in a reliable way
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) {
try {
} finally {
Copy link

davwheat commented Aug 3, 2023

I know this is really old now, but where does BottomSheetSettledResource come from? It's not included in the article you've written up. Thanks!

Copy link

cmathew commented Aug 3, 2023

@davwheat thanks for checking out my post! Here's the source for BottomSheetSettledResource:

class BottomSheetSettledResource(
  bottomSheetBehavior: BottomSheetBehaviorWrapper,
) : BottomSheetResource(bottomSheetBehavior) {

  override fun getName(): String {

  override fun isDesiredState(@BottomSheetBehavior.State state: Int): Boolean {
    return state != BottomSheetBehavior.STATE_DRAGGING && state != BottomSheetBehavior.STATE_SETTLING

Copy link

davwheat commented Aug 3, 2023

Thanks for getting back to me even after so many year since your post! Thanks for the help :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment