How to assert inside a RecyclerView in Espresso?

后端 未结 11 1825
故里飘歌
故里飘歌 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:05

    Danny Roa's solution is awesome, but it didn't work for the off-screen items I had just scrolled to. The fix is replacing this:

    View targetView = recyclerView.getChildAt(this.position)
                                  .findViewById(this.viewId);
    

    with this:

    View targetView = recyclerView.findViewHolderForAdapterPosition(this.position)
                                  .itemView.findViewById(this.viewId);
    

    ... in the TestUtils class.

提交回复
热议问题