Issue
The snippet of my code looks like this:
private void SelectOnline(String env) {
onView(withText("Some Text")).perform(click());
if (onView(withText(env)).check(matches(isChecked()))) {
onView(withId(R.id.dialogCancel)).perform(click());
}else {
onView(withText(env)).perform(click());
}
}
I got an error with message
required: boolean
found: ViewInteraction
This means that you cannot use espresso View Matchers as a condition for if..else. Is there some other way to implement if..else statement ?
Solution
Espresso was designed in a way to discourage devs from using conditionals, so there's no officially supported way to do this.
However, there are hacks you can try. I use try/catch statements. In your case, it would be something along the lines of:
private void SelectTransitBackendOnline(String env) {
onView(withText("Some Text")).perform(click());
try {
onView(withText(env)).check(matches(isChecked())))
onView(withId(R.id.dialogCancel)).perform(click());
} catch (AssertionFailedError e) {
onView(withText(env)).perform(click());
}
}
Answered By - Tin Man
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.