Android How can I move NavigationDrawer from the Espresso test library?

I am creating a unit test from Espresso on Android. My project has a NavigationDrawer. I am creating a test that should move the NavigationDrawer and click a button. Understanding how to create a slide action in my test.

My current solution:

try
    {
        runTestOnUiThread(new Runnable()
        {

            @Override
            public void run()
            {
                DrawerLayout drawer = (DrawerLayout)getActivity().findViewById(R.id.drawer_layout);
                drawer.openDrawer(Gravity.LEFT);
            }
        });
    }
    catch (Throwable e)
    {
        e.printStackTrace();
    }

But I think this is bad code.

+4
source share
4 answers

There is a description of how to do this in the android test kit group explained by ValeraZakharov - link .

+8
source

Espresso 1.1 , Navigation Drawer ... , , : espresso-contrib, gradle

androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2'

" " -:

- Contrib, DrawerActions, espresso-contrib .

DrawerActions. - , . , ; EspressoSamples ...

+7

openDrawer () is deprecated, you can use this code. I can confirm that it works.

onView(withId(R.id.my_drawer_layout)).perform(DrawerActions.open());
+3
source

Support for NavigationDrawer will be available soon in the next release of Espresso. Currently, you can implement your own ViewAction, where you would add code inside your Runnable. This is an incomplete solution because you are likely to encounter time problems associated with opening / closing a drawer. Espresso 1.1 will take care of this.

0
source

All Articles