1

Is there any possibility:

- to disable all animation for recycler view or run them on UI thread for testing with espresso?

Or

- to add idlingresources to android.support.v7.recyclerview.extensions.ListAdapter?

The problem is the following: The exception is thrown for Espresso test

android.support.test.espresso.PerformException: Error performing 'android.support.test.espresso.contrib.RecyclerViewActions$ActionOnItemAtPositionViewAction@3d4956f' on view 'with id: XXX:id/items_rcv'.

When trying to execute the following code:

//... code that executes recyclerView.adapter.submitList(items)
onView(withId(R.id.items_rcv))
            .perform(RecyclerViewActions.actionOnItemAtPosition<ViewHolder>(
                0, click()
            ));

The problem is that items are not visible when a click action is executed. They are shown with some delay because adapter for RecyclerView is extended from android.support.v7.recyclerview.extensions.ListAdapter:

class ItemsAdapter : ListAdapter<Item, RecyclerView.ViewHolder>() {
...
}

so it uses the AsyncListDiffer which shows items in recycler view with some animation.

Thank You in advance

UPDATE:

The following does not help: 1) set BackgroundThreadExecutor as MainThreadExecutor for AsyncListDiffer

ItemsAdapter(AsyncDifferConfig.Builder<Item>(ItemsDiffCallback)
                    .setBackgroundThreadExecutor(MainThreadExecutor())
                    .build())

2) disable itemAnimator for RecyclerView

mActivityTestRule.activity.findViewById<RecyclerView>(R.id.items_rcv).itemAnimator = null
tarashor
  • 11
  • 4

1 Answers1

-1

You can create a CountingIdlingResource and increment before you populate your List and decrement after its all done.

Just remember to register the IdlingResource on your @Before and @After, like so

IdlingRegistry.getInstance().register(rule.getIdlingResource()); //before
IdlingRegistry.getInstance().unregister(rule.getIdlingResource()); //after
Carlos
  • 388
  • 2
  • 13
  • 33
  • Do you know any callback in ListAdapter for decrementing after its all done? – tarashor Dec 26 '18 at 17:19
  • https://stackoverflow.com/questions/29173588/how-do-i-check-when-my-listview-has-finished-redrawing/29173680#29173680 – Carlos Dec 26 '18 at 17:55