Espresso - How to check if one of the view is displayed

后端 未结 10 2166
心在旅途
心在旅途 2021-02-03 17:22

In my test, after one action, there are two possible views which can appear and both of them are correct. How can I check if one of the view is displayed. For a single view I ca

10条回答
  •  没有蜡笔的小新
    2021-02-03 17:47

    I researched Espresso a bit, and I found this @ Espresso Samples.

    1. Search text "Asserting that a view is not displayed". It says "The above approach works if the view is still part of the hierarchy." So I think your code should work but you need to use ViewAssertions also. Using your code, perhaps do this:

      if (ViewAssertions.doesNotExist()) == null) {
         return;
      }
      onMyPageOne.check(matches(isDisplayed()));
      
    2. Another technique is check for UI existence. Search for text "Asserting that a view is not present". Using your code, my best suggestion is:

      onMyPageOne.check(doesNotExist());

    Note: This calls doesNotExist method.

    Their sample code is: onView(withId(R.id.bottom_left)).check(doesNotExist());

提交回复
热议问题