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

前端 未结 5 622
既然无缘
既然无缘 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条回答
  • 2020-12-25 09:43
    onView(withText("")).check(doesNotExist());
    
    0 讨论(0)
  • 2020-12-25 09:48

    Also work with yours method, but something like this:

    onView(withId(R.id.next)).check(matches(not(isDisplayed())));
    
    0 讨论(0)
  • 2020-12-25 09:51

    You can try this option if you check the view visibility "withEffectiveVisibility"

        onViewWithId(R.id.YOURVIEW).check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.GONE)))
    
    0 讨论(0)
  • 2020-12-25 09:52

    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.

    0 讨论(0)
  • 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());
    
    0 讨论(0)
提交回复
热议问题