To answer question 4, to which the accepted answer did not answer, I changed the following code, which I found here in the "Stack Overflow" section ( link ) to verify that.
@NonNull public static ViewInteraction getRootView(@NonNull Activity activity, @IdRes int id) { return onView(withId(id)).inRoot(withDecorView(not(is(activity.getWindow().getDecorView())))); }
The passed id is the View identifier displayed in your dialog box. You can also write a method as follows:
@NonNull public static ViewInteraction getRootView(@NonNull Activity activity, @NonNull String text) { return onView(withText(text)).inRoot(withDecorView(not(is(activity.getWindow().getDecorView())))); }
And now it is looking for a View containing a specific text string.
Use it like this:
getRootView(getActivity(), R.id.text_id).perform(click());
AutonomousApps Dec 08 '15 at 23:07 2015-12-08 23:07
source share