Android – How to click on an item on a navigation drawer using Espresso?


I am new to Android development. I want to use Espresso to test that my drawer opens, then click on an item and check that it opens a new activity. I’ve been searching for examples about this but haven’t had any luck.


public void clickOnYourNavigationItem_ShowsYourScreen() {
    // Open Drawer to click on navigation.
        .check(matches(isClosed(Gravity.LEFT))) // Left Drawer should be closed.
        .perform(; // Open Drawer

    // Start the screen of your activity.

    // Check that you Activity was opened.
    String expectedNoStatisticsText  InstrumentationRegistry.getTargetContext()

This does exactly what you are looking for.

Other examples are available here or here

Answered By – GVillani82

Leave a Comment