with a normal textview you could write a small Matcher that checks if getEllipsisCount is greater than 0. With the toolbar, unless you have a custom TextView for the tile, it is slightly more tricky. You will have to look in the Toolbar views for the title view (using getChildAt and getChildCount) and doing the same check. Something like
val matcher = object : BoundedMatcher<View, Toolbar>(Toolbar::class.java) {
override fun describeTo(description: Description?) {
}
override fun matchesSafely(item: Toolbar?): Boolean {
for (i in 0 until (item?.childCount ?: 0)) {
val v = item?.getChildAt(i)
(v as? TextView)?.let {
// check somehow that this textview is the title
val lines = it.layout.lineCount
if (it.layout.getEllipsisCount(lines - 1) > 0) {
return true
}
}
}
return false
}
}
and then use it like
onView(withId(R.id.action_bar)).check(matches(matcher))
haven't test it myself - but you get the idea. Also you can check the code LayoutMatchers to take some inspirations