lundi 27 avril 2015

Android Espresso: How to check that Toast message is NOT shown?

I'm working now in my functional test and in one of them I have to test that a toast message is NOT shown. Considering this is the code I'm using to check if the toast message is shown (this code works):

onView(withText(R.string.my_toast_message))
        .inRoot(withDecorView(not(getActivity().getWindow().getDecorView())))
        .check(matches(isDisplayed()));

below you can find the code I'm using to check that a toast message is NOT shown (none of them work):

Approach one:

onView(withText(R.string.error_invalid_login))
        .inRoot(withDecorView(not(getActivity().getWindow().getDecorView())))
        .check(matches(not(isDisplayed())));

Approach two:

onView(withText(R.string.error_invalid_login))
        .inRoot(withDecorView(not(getActivity().getWindow().getDecorView())))
        .check(doesNotExist());

Any idea about how can I check that a toast message is hot shown would be really appreciate :)

Aucun commentaire:

Enregistrer un commentaire