Android Espresso:如何断言不应显示视图
Android Espresso: How do I assert that a view should not be displayed
这似乎是正确的...
onView (withId (R.id.menu_delete)).check (matches (not (isDisplayed ())));
...但是它抛出这个异常:
android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: com.just10.android:id/menu_delete
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:com.github.ksoichiro.android.observablescrollview.ObservableListView{3169f0f3 VFED.VC. .F...... 0,0-480,724 #102000a android:id/list}
断言不应显示视图的最佳方法是什么?
我应该用的是这个:
onView(withId(R.id.menu_delete))
.check(doesNotExist());
这可能是因为视图位于选项菜单中,并且在任何给定时间可能存在也可能不存在,具体取决于 onCreateOptionsMenu 和 onPrepareOptionsMenu 中的实现
编辑
这是另一种适用于非菜单视图的方法:
onView (withID(R.id.menu_delete))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
这似乎是正确的...
onView (withId (R.id.menu_delete)).check (matches (not (isDisplayed ())));
...但是它抛出这个异常:
android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: com.just10.android:id/menu_delete
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:com.github.ksoichiro.android.observablescrollview.ObservableListView{3169f0f3 VFED.VC. .F...... 0,0-480,724 #102000a android:id/list}
断言不应显示视图的最佳方法是什么?
我应该用的是这个:
onView(withId(R.id.menu_delete))
.check(doesNotExist());
这可能是因为视图位于选项菜单中,并且在任何给定时间可能存在也可能不存在,具体取决于 onCreateOptionsMenu 和 onPrepareOptionsMenu 中的实现
编辑
这是另一种适用于非菜单视图的方法:
onView (withID(R.id.menu_delete))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)));