Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Espresso: How do I assert that a view should not be displayed

This would seem to be correct...

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

...but it 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's the best way to assert a view should not be displayed?

like image 608
Cory Roy Avatar asked Jun 19 '15 18:06

Cory Roy


People also ask

How do you check espresso visibility?

One simple way to check for a View or its subclass like a Button is to use method getVisibility from View class. I must caution that visibility attribute is not clearly defined in the GUI world. A view may be considered visible but may be overlapped with another view, for one example, making it hidden.

What is Espresso test Recorder?

The Espresso Test Recorder tool lets you create UI tests for your app without writing any test code. By recording a test scenario, you can record your interactions with a device and add assertions to verify UI elements in particular snapshots of your app.

What is Espresso android Studio?

Overview. Espresso is a UI test framework (part of the Android Testing Support Library) that allows you to create automated UI tests for your Android app.


1 Answers

What I should have used is this:

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

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

EDIT

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

onView (withID(R.id.menu_delete))
  .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
like image 116
Cory Roy Avatar answered Oct 09 '22 13:10

Cory Roy