How to assert inside a RecyclerView in Espresso?

后端 未结 11 1811
故里飘歌
故里飘歌 2020-12-02 06:38

I am using espresso-contrib to perform actions on a RecyclerView, and it works as it should, ex:

onView(withId(R.id.recycler_view))
.perform(Rec         


        
11条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-02 07:01

    Just to enhance riwnodennyk's answer, if your ViewHolder is a ViewGroup instead of a direct View object like TextView, then you can add hasDescendant matcher to match the TextView object in the ViewGroup. Example:

    onView(withId(R.id.recycler_view))
        .check(matches(atPosition(0, hasDescendant(withText("First Element")))));
    

提交回复
热议问题