The following statement does not work because doesNotExist()
returns a ViewAssertion
instead of a matcher. Any way to make it work without a try-catch
?
.check(either(matches(doesNotExist())).or(matches(not(isDisplayed()))));
If you want to check if a view doesn't not exist in the hierarchy, please use below assertion.
ViewInteraction.check(doesNotExist());
If you want to check if a view exist in the hierarchy but not displayed to the user, please use below assertion.
ViewInteraction.check(matches(not(isDisplayed())));
Hope this helps.
I had the same issue, one of my views will not have a certain view initially but could add it and hide it later. Which state the UI was in depended on wether background activities were destroyed.
I ended up just writing a variation on the implementation of doesNotExist:
public class ViewAssertions {
public static ViewAssertion doesNotExistOrGone() {
return new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException noView) {
if (view != null && view.getVisibility() != View.GONE) {
assertThat("View is present in the hierarchy and not GONE: "
+ HumanReadables.describe(view), true, is(false));
}
}
};
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With