I'm trying to write some tests with the new android-test-kit (Espresso). But I can't find any information on how to check if a dialog is displayed and perform some actions on it (like clicking the positive and negative buttons, e.t.c.). Note that a dialog may be also displayed by a WebView
, not by the application it self.
Any help would be appreciated. I just need a link, or some example code for the basics:
setCancelable(false)
was called on the dialog builder and we want to check that)Thank you in advice!
To verify if dialog appears you can simply check if View with a text that present inside the dialog is shown:
onView(withText("dialogText")).check(matches(isDisplayed()));
or, based on text with id
onView(withId(R.id.myDialogTextId)).check(matches(allOf(withText(myDialogText), isDisplayed()));
To click on dialogs button do this (button1 - OK, button2 - Cancel):
onView(withId(android.R.id.button1)).perform(click());
UPDATE