In case anyone needs other example on how to do it or need to assert MaxProgress, color and Progress. My answer is in Kotlin, I forked from this Java answer: https://stackoverflow.com/a/58964772/11793333.
fun matchesProgressBarTintAndMaxProgress(
expectedResourceId: ColorStateList?,
maxExpected: Int,
progressExpected: Int?
): Matcher<View?>? {
return object : BoundedMatcher<View?, View>(View::class.java) {
var actualColor: ColorStateList? = null
var actualMaxProgress = 0
var actualProgress = 0
var message: String? = null
override fun matchesSafely(item: View): Boolean {
actualColor = (item as ProgressBar).progressTintList
actualMaxProgress = item.max
actualProgress = item.progress
return actualColor == expectedResourceId && actualMaxProgress == maxExpected && actualProgress == progressExpected
}
override fun describeTo(description: Description) {
message = ("Tint color match: ${actualColor == expectedResourceId} "
+ "MaxProgress match: ${actualMaxProgress == maxExpected} "
+ "ActualProgress match: ${actualProgress == progressExpected}")
description.appendText(message)
}
}
}
To use it:
onView(withId(R.id.progressBar)).check(
matches(
matchesProgressBarTintAndMaxProgress(
ColorStateList.valueOf(
ContextCompat.getColor(
context,
R.color.red
)
),
100,
50
)
)
)