openDrawer from espresso contrib is deprecated

2019-03-17 19:41发布

问题:

Espresso contrib (com.android.support.test.espresso:espresso-contrib:2.2.1) openDrawer method is deprecated

then how should I open a drawer?

回答1:

Here's an example on how to use the new open and close methods:

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

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



回答2:

The documentation for openDrawer suggests using the open method with the correct resource id and perform 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)



回答3:

You can try this out! This will get the menu from toolbar, and press a click on him

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