我想測試UI視圖的缺席。該視圖選擇如下:匹配(不(isDisplayed()))與NoMatchingViewException失敗
public static ViewInteraction onMyTestUi() {
return onView(withId(R.id.myTestId));
}
選擇器工作正常,檢查是否顯示視圖,但給出瞭如果沒有顯示的視圖檢查錯誤。我使用這個如下:
onMyTestUi().check(matches(not(isDisplayed())));
,但我得到了以下錯誤:
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會拋出錯誤? 請在這裏建議可能會出錯的地方。
謝謝, 驚訝!
它不爲我工作,但'onView(withId(R.id.myTestId))檢查(匹配(不(isDisplayed())));'沒有工作。 – Sithu 2016-04-21 05:39:00
@Sithu - 這取決於應用程序。 如果您正在查找的視圖存在於視圖層次結構中但不可見,那麼您需要使用not(isDisplayed)。但是,如果視圖不存在於視圖層次結構中,則需要使用doesNotExist()。 – user846316 2016-04-21 11:42:38
我在佈局中有按鈕,但是在用戶角色設置'onCreate'中的'View.GONE'的可見性。那麼,這是否意味着它處於視圖層次結構中並且不可見? – Sithu 2016-04-22 02:31:07