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 per
If you have an AlertDialog like that:
You can check if the components are displayed:
int titleId = mActivityTestRule.getActivity().getResources()
.getIdentifier( "alertTitle", "id", "android" );
onView(withId(titleId))
.inRoot(isDialog())
.check(matches(withText(R.string.my_title)))
.check(matches(isDisplayed()));
onView(withId(android.R.id.text1))
.inRoot(isDialog())
.check(matches(withText(R.string.my_message)))
.check(matches(isDisplayed()));
onView(withId(android.R.id.button2))
.inRoot(isDialog())
.check(matches(withText(android.R.string.no)))
.check(matches(isDisplayed()));
onView(withId(android.R.id.button3))
.inRoot(isDialog())
.check(matches(withText(android.R.string.yes)))
.check(matches(isDisplayed()));
and perform an action:
onView(withId(android.R.id.button3)).perform(click());