Skip to content

Instantly share code, notes, and snippets.

@RankoR
Created November 6, 2018 16:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save RankoR/36b3c3b8972224de55704d31f41b2097 to your computer and use it in GitHub Desktop.
Save RankoR/36b3c3b8972224de55704d31f41b2097 to your computer and use it in GitHub Desktop.
Extend Espresso to make Snackbar testing easier. Note: this code works only for AndroidX.
import androidx.annotation.StringRes
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.ViewInteraction
import androidx.test.espresso.matcher.ViewMatchers
import org.hamcrest.CoreMatchers
import org.hamcrest.CoreMatchers.allOf
fun onSnackbar(@StringRes withText: Int): ViewInteraction {
return onView(
CoreMatchers.allOf(
ViewMatchers.withId(com.google.android.material.R.id.snackbar_text),
ViewMatchers.withText(withText)
)
)
}
fun onSnackbarButton(@StringRes withText: Int): ViewInteraction {
return onView(
allOf(
ViewMatchers.withId(com.google.android.material.R.id.snackbar_action),
ViewMatchers.withText(withText)
)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment