21

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

then how should I open a drawer?

Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
Daniel Gomez Rico
  • 15,026
  • 20
  • 92
  • 162

3 Answers3

43

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());

Androiderson
  • 16,865
  • 6
  • 62
  • 72
  • I have the following problem, after using these lines to open the drawer, the next operation, which performs a click on the item inside the drawer, fails because the drawer closes instantly. What could cause a close drawer when there is no other operation after that? – X-HuMan Nov 24 '16 at 16:21
4

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)

kevintcoughlin
  • 474
  • 4
  • 15
1

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());
Catluc
  • 1,775
  • 17
  • 25