For Android apps, how do I check what resource ID is being used in a specific image view?-ThrowExceptions

Exception or error:

I’m writing automated tests for my company’s app. The tests use a combination of Espresso and Robotium. Several of those tests are supposed to check whether certain ReactImageView elements are displaying a specific image.

I first tried using hasBackground() as follows:


However, this returns a NoMatchingViewException.

I then tried Daniele Bottillo’s matcher as described here:

onView(allOf(..., new DrawableMatcher(R.drawable....), isDisplayed())).check(matches(isDisplayed()));

But this didn’t work either:

java.lang.ClassCastException: com.facebook.drawee.generic.RootDrawable cannot be cast to

Lastly, I tried Frankie Sardo’s solution: Android Espresso match BitmapDrawables with different tint

onView(allOf(..., withImageDrawable(R.drawable...), isDisplayed())).check(matches(isDisplayed()));

However, this again throws a NoMatchingViewException. I’m running out of ideas. Is it even possible to check what resource is attached to an image view?

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *