Chad Bingham Chad Bingham - 1 year ago 904
Android Question

Espresso: return boolean if view exists

I am trying to check to see if a view is displayed with Espresso. Here is some pseudo code to show what I am trying:

if (!Espresso.onView(withId({
// then do something
} else {
// do nothing, or what have you

But my problem is
does not return boolean. It is just an assertion. With UiAutomator I was able to just do something like so:

if (UiAutomator.getbyId(SomeId).exists){

I found this; check line 46. Still can't find out how to use it.

Answer Source

We need that functionality and I ended up implementing it below:

if(onView(withText("click OK to Continue")).exists()){ 
} else { 

I hope it is useful for you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download