Issue
Based on what I see in Espresso cheat sheet, there are two methods that check visibility of a View, isDisplayed()
and isCompletelyDisplayed()
.
I have sliding layout in my main screen and I have several views in it. I'm checking one of them by following command:
onView(withId(R.id.payment_btn)).check(matches(isDisplayed()));
However, test stops and displays following error:
android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'is displayed on the screen to the user' doesn't match the selected view.
Expected: is displayed on the screen to the user
Then I thought that since the View is not visible I can test it by following test:
onView(withId(R.id.payment_btn)).check(doesNotExist());
However, test stopped and displayed following message:
android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: View is present in the hierarchy:
Expected: is <false>
Got: <true>
So, how can I check visibility of a View off the screen?
Solution
When the view is outside the screen, it is not displayed, but it still exist in the view hierarchy. To check that the view is not displayed on the screen use: onView(withId(R.id.payment_btn)).check(matches(not(isDisplayed())));
If you want to check if it is displayed, you have to scroll/swipe to the view, so it becomes visible.
Answered By - HowieH
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.