【发布时间】:2020-02-20 08:41:07
【问题描述】:
我的测试用例相当简单:在主活动视图上,我有一个抽屉。此抽屉中的一个菜单项打开一个对话框。我想断言,单击此菜单项,在打开对话框之前关闭抽屉。
这是我现在拥有的:
// 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()))
请注意,我还不想关闭对话框。因为目标是断言抽屉在显示对话框之前/期间已关闭。
问题是最后一条指令将上升一个NoMatchingViewException,因为抽屉似乎不再在视图层次结构中。看起来显示对话框使其成为视图层次结构的新根。不过,我知道活动视图存在于某处。我想知道,在这种情况下,当它显示时如何匹配对话框下的 vie。
【问题讨论】: