Arcane Android: espresso with a navigation drawer

Alec Holmes
1 min readMar 13, 2016

--

  • Applies to espresso-core & espresso-contrib v2.2.1

The problem

I want to write an espresso test that opens the nav drawer and clicks on a menu item.

Failed Solution

At first glance this seems like it should be simple!

  1. Open the Drawer using the DrawerActions found in com.android.support.test.espresso:espresso-contrib:2.2.1
  2. Find the view with the id we want and click on it.

This failed!No views in hierarchy with id”. After some googling I stumbled across the following working solution.

Working Solution

In order to perform actions on the navigation drawer you must copy the NavigationViewActions.java into your app found in the android testing samples repo.

https://raw.githubusercontent.com/googlecodelabs/android-testing/master/app/src/androidTest/java/com/example/android/testing/notes/custom/action/NavigationViewActions.java

In November 2015 a Stephan Linzner suggested this class will be in the next release of espresso so something to look forward to ^_^.

Happy testing!

--

--