Issue
Typically if we wanted to press a button using espresso you would wait for the view with ID to be loaded. Then Perform click. Material design chip lets you define a close icon and place a listener on the close Icon. However, this means the closeIcon doesn't have an ID to reference directly and shows up as part of the Chip during layout inspector.
onView(withId(R.id.chip)).perform(click())
How would you use espresso to find the close Icon?
Solution
No easy way to do it with an espresso expression but after fiddling with it, it seemed Material Chip exposes a performCloseIconClick() function that I ultimately plugged into a Custom View Action. Hope this helps a few of you.
class ClickCloseIconAction : ViewAction {
override fun getConstraints(): Matcher<View> {
return ViewMatchers.isAssignableFrom(Chip::class.java)
}
override fun getDescription(): String {
return "click drawable "
}
override fun perform(uiController: UiController, view: View) {
val chip = view as Chip//we matched
chip.performCloseIconClick()
}
}
This means you can call it like so
onView(withId(R.id.chip)).perform(ClickCloseIconAction())
Answered By - Randy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.