Android. How do I drag the Espresso Test Library navigation drawer?

advertisements

I create unit-test from Espresso in Android. My project has NavigationDrawer. I create test which must slide NavigationDrawer and click on button. In understand, how create 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 it's bad code.


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