My test case is fairly simple: on the main activity view, I have a drawer. One menu item in this drawer opens a dialog. I want to assert that, this menu item is clicked, the drawer is closed before the dialog is opened.
Here is what I have now:
// Opens the drawer
onView(withId(R.id.activity_main_navigation_drawer)).perform(DrawerActions.open())
// Check that the drawer is opened
onView(withId(R.id.activity_main_navigation_drawer)).check(matches(isOpen()))
// Click on the menu item that closes the drawer and display the dialog
onView(withText(R.string.title_add_subscription)).perform(click())
// Check that the drawer is now closed: this won't work
onView(withId(R.id.activity_main_navigation_drawer)).check(matches(isClosed()))
Note that I don't want to dismiss the dialog yet. Because the goal is to assert that the drawer was closed before/during the display of the dialog.
The problem is the last instruction will rise a NoMatchingViewException
as the drawer doesn't seem to be in the view herarchy anymore. It looks like displaying the dialog make it the new root of the view hirarchy. Still, I know that the activity view exists somewhere. I'd like to know, in this case, how to match the vie under the dialog when it is shown.