matches(not(isDisplayed())) fails with NoMatchingViewException

前端 未结 5 626
既然无缘
既然无缘 2020-12-25 09:25

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         


        
5条回答
  •  -上瘾入骨i
    2020-12-25 10:02

    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());
    

提交回复
热议问题