来自 espresso contrib 的 openDrawer 已弃用

openDrawer from espresso contrib is deprecated

Espresso contrib (com.android.support.test.espresso:espresso-contrib:2.2.1) openDrawer 方法已弃用

那我应该怎么打开抽屉呢?

openDrawer 的文档建议使用具有正确资源 ID 的 open 方法并执行 ViewAction

Use open() with perform after matching a view. This method will be removed in the next release.


http://developer.android.com/reference/android/support/test/espresso/contrib/DrawerActions.html#open(int)

以下是有关如何使用新的 openclose 方法的示例:

onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());

onView(withId(R.id.drawer_layout)).perform(DrawerActions.close());

你可以试试这个!这将从工具栏中获取菜单,然后单击他

onView(allOf(withContentDescription("Menu"),
             withParent(withId(R.id.toolbar)),
             isDisplayed())).perform(click());