I am trying to test the absence of the UI view. The view selector is as follows:
public static ViewInteraction onMyTestUi() {
return onView(withId(R.id.m
onView(withText("")).check(doesNotExist());
Also work with yours method, but something like this:
onView(withId(R.id.next)).check(matches(not(isDisplayed())));
You can try this option if you check the view visibility "withEffectiveVisibility"
onViewWithId(R.id.YOURVIEW).check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.GONE)))
Need to use doesNotExist()
instead.
Found here.
If the view is there in the view hierarchy but in an invisible state (visibility is set to 'INVISIBLE'), use not(isDisplayed)
. However, if the view is not there at all in the view hierarchy (e.g. visibility set to 'GONE'), doesNotExist()
is used.
If you want to check if View
is either not visible or does not exist.
public static ViewAssertion isNotDisplayed() {
return new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException noView) {
if (view != null && isDisplayed().matches(view)) {
throw new AssertionError("View is present in the hierarchy and Displayed: "
+ HumanReadables.describe(view));
}
}
};
}
Usage:
onView(withId(R.id.someView)).check(isNotDisplayed());