如果显示吐司,是否可能返回true

时间:2019-05-08 16:35:12

标签: android android-espresso ui-testing

如果我需要检查是否显示了烤面包,则使用此:

viewWithTextResId(server_error).inRoot(ToastMatcher())
                .checkDisplayed()

fun ViewInteraction.checkDisplayed(): ViewInteraction {
    return check(matches(isDisplayed()))
}

class ToastMatcher : TypeSafeMatcher<Root>() {

    override fun describeTo(description: Description) {
        description.appendText("is toast")
    }

    override fun matchesSafely(root: Root): Boolean {
        val type = root.getWindowLayoutParams().get().type
        if (type == WindowManager.LayoutParams.TYPE_TOAST) {
            val windowToken = root.getDecorView().getWindowToken()
            val appToken = root.getDecorView().getApplicationWindowToken()
            if (windowToken === appToken) {
                return true
            }
        }
        return false
    }
}

很好,工作正常。 但是我需要测试,如果吐司是show / hide,则返回boolean。

0 个答案:

没有答案