Espresso how to search for text and if the text is displayed click on it still continue the test

I want to click on the OK OK button which is only displayed the first time,

In robotium, this statement does it

if(solo.searchText("OK")){
        solo.clickOnText("OK");
    }else{
        //Do other things
}

      

If the OK text is not displayed, the test should not fail, it should continue, but the espresso test fails when the application is run a second time because the timing tutorial is not displayed.

In espresso

onView(withText("OK")).check(matches(isDisplayed())).perform(click());

      

asssertion doesn't work here, I want to have a boolean return value for the text OK so that if the OK button is not shown the test should continue.

+3


source to share


1 answer


I don't know how to do the if / else in Espresso, but the workaround I did was add an external tool "adb uninstall your app", this gave me a clean working environment for each test run.



-2


source







All Articles