Skip to content

Instantly share code, notes, and snippets.

@cmathew
Created May 5, 2021 00:19
Show Gist options
  • Save cmathew/8a1dcee0fa3d01f64257ee66d3407283 to your computer and use it in GitHub Desktop.
Save cmathew/8a1dcee0fa3d01f64257ee66d3407283 to your computer and use it in GitHub Desktop.
Custom Espresso entry points
/** Modified default root matcher at {@link androidx.test.espresso.matcher.RootMatchers.DEFAULT} */
internal val activityRootMatcher: Matcher<Root> = allOf(
hasWindowLayoutParams(),
allOf(
IsSubwindowOfCurrentActivity(),
isFocusable()
)
)
/** Modified default root matcher at {@link androidx.test.espresso.matcher.RootMatchers.DEFAULT} */
internal val dialogRootMatcher: Matcher<Root> = allOf(
hasWindowLayoutParams(),
allOf(
allOf(isDialog(), withDecorView(HasWindowFocus())),
isFocusable()
)
)
fun onView(viewMatcher: Matcher<View>): ViewInteraction {
return Espresso.onView(viewMatcher).inRoot(activityRootMatcher)
}
fun onBottomSheetView(viewMatcher: Matcher<View>): ViewInteraction {
return Espresso.onView(viewMatcher).inRoot(dialogRootMatcher)
}
fun onDialogView(viewMatcher: Matcher<View>): ViewInteraction {
return Espresso.onView(viewMatcher).inRoot(dialogRootMatcher)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment