Вы можете создать пользовательский ViewAction
для отклонения IntroductoryOverlay
с помощью его функции remove :
fun hideIntroductoryOverlay(): ViewAction = object : ViewAction {
override fun getDescription(): String = "hide introductory overlay"
override fun getConstraints(): Matcher<View> = isRoot()
override fun perform(uiController: UiController, view: View) {
val matcher = any(IntroductoryOverlay::class.java)
val matches = TreeIterables.breadthFirstViewTraversal(view).filter(matcher::matches)
val overlay = matches[0] as IntroductoryOverlay
overlay.remove()
}
}
Если фильтр возвращает пустой массив, это означает, что нет IntroductoryOverlay
найден. Если размер массива больше 1, это означает, что найдено более одного IntroductoryOverlay
. В противном случае, чтобы отклонить его:
onView(isRoot()).perform(hideIntroductoryOverlay())
Вы также можете проверить, активен ли IntroductoryOverlay
с пользовательским ViewMatcher
:
fun hasIntroductoryOverlay(): Matcher<View> = object : BoundedMatcher<View, ViewGroup>(ViewGroup::class.java) {
override fun describeTo(description: Description) {
description.appendText("has introductory overlay")
}
override fun matchesSafely(item: ViewGroup): Boolean {
val matcher = any(IntroductoryOverlay::class.java)
return TreeIterables.breadthFirstViewTraversal(item).any(matcher::matches)
}
}
И выполнить проверку при просмотре root :
onView(isRoot()).check(matches(hasIntroductoryOverlay()))