Search in sources :

Example 1 with ViewAction

use of com.google.android.apps.common.testing.ui.espresso.ViewAction in project double-espresso by JakeWharton.

the class DrawerActions method checkDrawer.

/**
   * Returns true if the given matcher matches the drawer.
   */
private static boolean checkDrawer(int drawerLayoutId, final Matcher<View> matcher) {
    final AtomicBoolean matches = new AtomicBoolean(false);
    onView(withId(drawerLayoutId)).perform(new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return isAssignableFrom(DrawerLayout.class);
        }

        @Override
        public String getDescription() {
            return "check drawer";
        }

        @Override
        public void perform(UiController uiController, View view) {
            matches.set(matcher.matches(view));
        }
    });
    return matches.get();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ViewAction(com.google.android.apps.common.testing.ui.espresso.ViewAction) Matcher(org.hamcrest.Matcher) UiController(com.google.android.apps.common.testing.ui.espresso.UiController) DrawerLayout(android.support.v4.widget.DrawerLayout) Espresso.onView(com.google.android.apps.common.testing.ui.espresso.Espresso.onView) View(android.view.View)

Example 2 with ViewAction

use of com.google.android.apps.common.testing.ui.espresso.ViewAction in project double-espresso by JakeWharton.

the class DrawerActions method registerListener.

/**
   * Returns a {@link ViewAction} that adds an {@link IdlingDrawerListener} as a drawer listener to
   * the {@link DrawerLayout}. The idling drawer listener wraps any listener that already exists.
   */
private static ViewAction registerListener() {
    return new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return isAssignableFrom(DrawerLayout.class);
        }

        @Override
        public String getDescription() {
            return "register idling drawer listener";
        }

        @Override
        public void perform(UiController uiController, View view) {
            DrawerLayout drawer = (DrawerLayout) view;
            DrawerListener existingListener = getDrawerListener(drawer);
            if (existingListener instanceof IdlingDrawerListener) {
                // listener is already registered. No need to assign.
                return;
            }
            drawer.setDrawerListener(IdlingDrawerListener.getInstance(existingListener));
        }
    };
}
Also used : ViewAction(com.google.android.apps.common.testing.ui.espresso.ViewAction) UiController(com.google.android.apps.common.testing.ui.espresso.UiController) DrawerLayout(android.support.v4.widget.DrawerLayout) Espresso.onView(com.google.android.apps.common.testing.ui.espresso.Espresso.onView) View(android.view.View) DrawerListener(android.support.v4.widget.DrawerLayout.DrawerListener)

Aggregations

DrawerLayout (android.support.v4.widget.DrawerLayout)2 View (android.view.View)2 Espresso.onView (com.google.android.apps.common.testing.ui.espresso.Espresso.onView)2 UiController (com.google.android.apps.common.testing.ui.espresso.UiController)2 ViewAction (com.google.android.apps.common.testing.ui.espresso.ViewAction)2 DrawerListener (android.support.v4.widget.DrawerLayout.DrawerListener)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Matcher (org.hamcrest.Matcher)1