【发布时间】:2016-12-23 08:04:38
【问题描述】:
以下语句不起作用,因为 doesNotExist() 返回的是 ViewAssertion 而不是匹配器。没有try-catch,有什么方法可以让它工作吗?
.check(either(matches(doesNotExist())).or(matches(not(isDisplayed()))));
【问题讨论】:
-
你不喜欢
try-catch的什么? -
@SimonSchnell 它不太适合 hamcrest 匹配器的语法。我认为可能有更漂亮的解决方案。
-
在我看来这个说法是不正确的。
(not(isDisplayed()))用于检查层次结构中存在的视图是否未显示,但doesNotExist()验证层次结构中根本不存在视图。他们互相矛盾。 -
那
.check(either(matches(is(doesNotExist()))).or(matches(not(isDisplayed()))));` -
@piotrek1543 不能应用于 ViewAssertion,需要 hamcrest 匹配器。
标签: android android-espresso hamcrest