Android Espresso: how to claim that a view should not be displayed

It would seem that this is correct ...

onView (withId (R.id.menu_delete)).check (matches (not (isDisplayed ()))); 

... but this throws this exception:

 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} 

What is the best way to claim a view should not be displayed?

+7
android android-espresso
source share
1 answer

What I had to use is the following:

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

This may be due to the fact that the view is in the options menu and may or may not exist at any time, depending on the implementation in onCreateOptionsMenu and onPrepareOptionsMenu

EDIT

This is another method that worked for me for a non-menu:

 onView (withID(R.id.menu_delete)) .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); 
+14
source share

All Articles