7

I am trying to get the recycle view using onData but i am stuck in this error:

No views in hierarchy found matching: is assignable from class: class android.widget.AdapterView

The code is just this:

onData(allOf(isAssignableFrom(RecyclerView.class), withId(R.id.ce_musers_list)))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));

My adaptor extends RecyclerView.Adapter as it should for a RecycleView, yet, seams the matcher is looking for a simple Adapter. This is my first time with espress, so i may be failing in something basic.

My Espresso version is 3.0.0

MiguelSlv
  • 14,067
  • 15
  • 102
  • 169

2 Answers2

16

onData() is used only with the AdapterView and its subclasses, which RecyclerView does not belong to.

There is a helper class that espresso comes with: RecyclerViewActions that can be used to perform various actions on a recyclerview and itemviews of the viewholders.

For instance, if you want to make an assertion - you can scroll to the itemview and then use regular onView()... to check particulars of that viewholder.

Be_Negative
  • 4,892
  • 1
  • 30
  • 33
  • 1
    Let's use [RecyclerViewActions](https://developer.android.com/reference/androidx/test/espresso/contrib/RecyclerViewActions?hl=en) from androidX instead of the un-maintained package. – mrahimygk Dec 16 '19 at 07:11
1
    val recyclerView = onView(
        allOf(
            withId(R.id.myRecyclerView),
            childAtPosition(
                withClassName(`is`("androidx.constraintlayout.widget.ConstraintLayout")),
                0
            )
        )
    )
    recyclerView.perform(actionOnItemAtPosition<ViewHolder>(1, click()))
TheLastBorn
  • 69
  • 1
  • 2