如何检查不显示弹出通知。浓咖啡

问题描述 投票:3回答:1

我有弹出通知。我的第一个测试检查该通知是否已显示并成功通过。我使用下一个方法进行此测试:

fun viewInNotificationPopupIsDisplayed(viewMatcher: Matcher<View>) {
    onView(viewMatcher)
        .inRoot(RootMatchers.isPlatformPopup())
        .check(ViewAssertions.matches(isDisplayed()))
}

我在第二个测试用例中遇到问题,在该情况下,我必须检查我的弹出通知是否已经消失(意味着它不再显示了)。所以我正在尝试使用下一个方法:

    fun viewInNotificationPopupIsNotDisplayed(viewMatcher: Matcher<View>) {
        Espresso.onView(viewMatcher)
            .inRoot(RootMatchers.isPlatformPopup())
            .check(matches(not(isDisplayed())))
          //.check(ViewAssertions.doesNotExist())  // doesn't work as well
    }

我得到下一个例外:

android.support.test.espresso.NoMatchingRootException: 
Matcher 'with decor view of type PopupWindow$PopupViewContainer' 
did not match any of the following roots: 
[Root{application-window-token=android.view.ViewRootImpl$W@bb8371e,
 window-token=android.view.ViewRootImpl$W@bb8371e, has-window-focus=true, 

请,有人可以帮忙吗?

android kotlin android-espresso
1个回答
0
投票

[如果您有PopupWindow,因为抛出NoMatchingRootException的方式,看来浓缩咖啡无法进行这种简单的检查

您可能只捕获了异常并完成了测试,但这不是一个好选择,因为与默认测试用例相比,抛出并捕获NoMatchingRootException会花费大量时间。似乎是意式浓缩咖啡正在等待根源

对于这种情况,建议只是在这里放弃浓缩咖啡,并在此断言中使用UiAutomator

val device: UiDevice
   get() = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())

fun assertPopupIsNotDisplayed() {
    device.waitForIdle()
    assertFalse(device.hasObject(By.text(yourText))))
}

fun assertPopupIsDisplayed() {
    device.waitForIdle()
    assertTrue(device.hasObject(By.text(yourText))))
}
© www.soinside.com 2019 - 2024. All rights reserved.