Issue
I found on Stackoverflow something like that about checking when dialog is visible:
onView(withText("Yes"))
.inRoot(isDialog())
.check(matches(isDisplayed()))
.perform(click());
Of course this works if Dialog with button 'yes' is visible, but in different scenario, if dialog will be invisible I got crash:
android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with text: is "Yes"
So how to write that if the dialog exists, click yes, and if it does not exist, then nothing will be clicked?
Solution
You could try this:
onView(withText("Yes")).inRoot(isDialog()).withFailureHandler(new FailureHandler() {
@Override
public void handle(Throwable error, Matcher<View> viewMatcher){
}
}).check(matches(isDisplayed())).perform(customClick());
//if dialog is visible, perform click, otherwise do nothing.
Answered By - navylover
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.