Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android. How can I slide NavigationDrawer from Espresso test library?

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.

like image 360
Viacheslav Avatar asked Dec 19 '13 12:12

Viacheslav


People also ask

How to use navigation drawer in Android?

Add a navigation drawerThe drawer appears when the user touches the drawer icon in the app bar or when the user swipes a finger from the left edge of the screen. Figure 3. An open drawer displaying a navigation menu. The drawer icon is displayed on all top-level destinations that use a DrawerLayout .

How do I open a navigation drawer?

Android Navigation Drawer is a sliding left menu that is used to display the important links in the application. Navigation drawer makes it easy to navigate to and fro between those links. It's not visible by default and it needs to opened either by sliding from left or clicking its icon in the ActionBar.


1 Answers

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

like image 51
denys Avatar answered Nov 15 '22 04:11

denys