浓缩咖啡验证文本是否不存在不起作用



我想验证在数据库中的条目更改后从数据库条目检索的字符串不再存在,我为此使用以下语句:

onView(allOf(withText("oldname"), withId(R.id.title))).check(doesNotExist());

根据浓缩咖啡文档和其他帖子,我看到这应该有效,但我收到以下错误:

android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: (with text: is "oldname" and with id: com.myco.myapp:id/apkName)

问题是您正在寻找带有文本"oldname"的视图,然后试图断言它不存在,但这不起作用,因为视图不存在(因此您无法在其上断言任何内容(。

你从这里走向何方取决于你想要完成什么。如果视图根本不应该存在:

onView(withId(R.id.title)).check(doesNotExist());

如果视图应该在那里,但没有该文本:

onView(allOf(not(withText("oldname")),withId(R.id.title))).check(matches(isDisplayed());

或者它的变体:

onView(withId(R.id.title)).check(matches(not(withText("oldName"))));

第一个变体说"确保有一个具有该 id 而不是该文本的视图"。第二个变体说"确保具有该 id 的视图没有该文本"。

最新更新