match(not(isDisplayed()))失败,出现NoMatchingViewException [英] matches(not(isDisplayed())) fails with NoMatchingViewException

查看:112
本文介绍了match(not(isDisplayed()))失败,出现NoMatchingViewException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试测试UI视图的缺失.视图选择器如下:

I am trying to test the absence of the UI view. The view selector is as follows:

public static ViewInteraction onMyTestUi() {
    return onView(withId(R.id.myTestId));
}

选择器可以很好地检查视图是否显示,但是在检查视图是否未显示时会出错.我正在按如下方式使用它:

The selector works fine to check if the view is displayed, but gives error on checking if the view not displayed. I am using this as follows:

 onMyTestUi().check(matches(not(isDisplayed())));

但是出现以下错误:

com.google.android.apps.common.testing.ui.espresso.NoMatchingViewException: 找不到层次结构中符合以下条件的视图:ID为:是否为 目标视图不是视图层次结构的一部分,您可能需要使用 Espresso.onData从以下之一加载它 AdapterViews:android.widget.ListView {...}

com.google.android.apps.common.testing.ui.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: is If the target view is not part of the view hierarchy, you may need to use Espresso.onData to load it from one of the following AdapterViews:android.widget.ListView{...}

这很奇怪.我正在检查缺少UI,并且期望不会找到该视图.那为什么Espresso会抛出错误? 请在这里提出可能出问题的地方.

This is strange. I am checking the absence of the UI and its expected that this view won't be found. Then why Espresso is throwing error? Please suggest what might be going wrong here.

谢谢, 惊讶!

推荐答案

需要改用doesNotExist(). 在此处找到.

如果视图位于视图层次结构中但处于不可见状态(可见性设置为不可见"),请使用not(isDisplayed).但是,如果视图在视图层次结构中根本不存在(例如,可见性设置为"GONE"),则使用doesNotExist().

If the view is there in the view hierarchy but in an invisible state (visibility is set to 'INVISIBLE'), use not(isDisplayed). However, if the view is not there at all in the view hierarchy (e.g. visibility set to 'GONE'), doesNotExist() is used.

这篇关于match(not(isDisplayed()))失败,出现NoMatchingViewException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆