0

I have this test and I want to assert that a specific item is being loaded by retrofit and displyed in the recyclerview.

I already debugged and I know that the web request response is successful and returns the list of movies as expected.

 @Test
    fun findItem_checkItsText() {
        val result = tmdbApi.getMovies(AppConstants.LANGUAGE, 1).execute()

        if(result.isSuccessful) {
            val movieTitle = result.body()?.results?.get(0)?.title
            onView(withText(movieTitle)).check(matches(isDisplayed()))
        } else {
            AssertionFailedError()
        }


    }

The test fails with androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with text: is "Hustlers" message (Hustlers is the title of the movie at position 0) and I don't know why. How can I check if data is loaded and displayed in recyclerview items?

  • Possible duplicate of [How to assert inside a RecyclerView in Espresso?](https://stackoverflow.com/questions/31394569/how-to-assert-inside-a-recyclerview-in-espresso) – jeprubio Sep 30 '19 at 15:12
  • I suppose there is a ProgressBar while loading the info so that espresso will wait until the animations are stopped (the data is loaded) – jeprubio Sep 30 '19 at 15:14

1 Answers1

0

You can set Thread.sleep() between "val movieTitle" and "onView". If this work, create Idling resource for your text. (https://developer.android.com/training/testing/espresso/idling-resource)