How can I use Espresso to click a specific view inside a RecyclerView item? I know I can click the item at position 0 using:
onView(withId(R.i
You can even generalize this approach to support more actions not only click
. Here is my solution for this:
fun recyclerChildAction(@IdRes id: Int, block: T.() -> Unit): ViewAction {
return object : ViewAction {
override fun getConstraints(): Matcher {
return any(View::class.java)
}
override fun getDescription(): String {
return "Performing action on RecyclerView child item"
}
override fun perform(
uiController: UiController,
view: View
) {
view.findViewById(id).block()
}
}
}
And then for EditText
you can do something like this:
onView(withId(R.id.yourRecyclerView))
.perform(
actionOnItemAtPosition(
0,
recyclerChildAction(R.id.editTextId) { setText("1000") }
)
)