Search in sources :

Example 16 with UiController

use of android.support.test.espresso.UiController in project material-components-android by material-components.

the class TestUtilsActions method reinflateMenu.

/**
   * Clears and inflates the menu.
   *
   * @param menuResId The menu resource XML to be used.
   */
public static ViewAction reinflateMenu(@MenuRes final int menuResId) {
    return new ViewAction() {

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

        @Override
        public String getDescription() {
            return "clear and inflate menu " + menuResId;
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            final NavigationView nv = (NavigationView) view;
            nv.getMenu().clear();
            nv.inflateMenu(menuResId);
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : NavigationView(android.support.design.widget.NavigationView) ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) NavigationView(android.support.design.widget.NavigationView) TextView(android.widget.TextView) View(android.view.View)

Example 17 with UiController

use of android.support.test.espresso.UiController in project material-components-android by material-components.

the class DrawerLayoutActions method openDrawer.

/** Opens the drawer at the specified edge gravity. */
public static ViewAction openDrawer(final int drawerEdgeGravity) {
    return new ViewAction() {

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

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

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            DrawerLayout drawerLayout = (DrawerLayout) view;
            drawerLayout.openDrawer(drawerEdgeGravity);
            // Wait for a full second to let the inner ViewDragHelper complete the operation
            uiController.loopMainThreadForAtLeast(1000);
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) DrawerLayout(android.support.v4.widget.DrawerLayout) View(android.view.View)

Example 18 with UiController

use of android.support.test.espresso.UiController in project material-components-android by material-components.

the class DrawerLayoutActions method closeDrawer.

/** Closes the drawer at the specified edge gravity. */
public static ViewAction closeDrawer(final int drawerEdgeGravity) {
    return new ViewAction() {

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

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

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            DrawerLayout drawerLayout = (DrawerLayout) view;
            drawerLayout.closeDrawer(drawerEdgeGravity);
            // Wait for a full second to let the inner ViewDragHelper complete the operation
            uiController.loopMainThreadForAtLeast(1000);
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) DrawerLayout(android.support.v4.widget.DrawerLayout) View(android.view.View)

Example 19 with UiController

use of android.support.test.espresso.UiController in project material-components-android by material-components.

the class FloatingActionButtonActions method showThenHide.

public static ViewAction showThenHide(final int animDuration) {
    return new ViewAction() {

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

        @Override
        public String getDescription() {
            return "Calls show() then hide()";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            FloatingActionButton fab = (FloatingActionButton) view;
            fab.show();
            fab.hide();
            uiController.loopMainThreadForAtLeast(animDuration + 50);
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) FloatingActionButton(android.support.design.widget.FloatingActionButton) View(android.view.View)

Example 20 with UiController

use of android.support.test.espresso.UiController in project material-components-android by material-components.

the class FloatingActionButtonActions method setSize.

public static ViewAction setSize(@FloatingActionButton.Size final int size) {
    return new ViewAction() {

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

        @Override
        public String getDescription() {
            return "Sets FloatingActionButton size";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            final FloatingActionButton fab = (FloatingActionButton) view;
            fab.setSize(size);
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) FloatingActionButton(android.support.design.widget.FloatingActionButton) View(android.view.View)

Aggregations

UiController (android.support.test.espresso.UiController)56 View (android.view.View)56 ViewAction (android.support.test.espresso.ViewAction)55 NavigationView (android.support.design.widget.NavigationView)17 TextView (android.widget.TextView)11 ViewPager (android.support.v4.view.ViewPager)8 TabLayout (android.support.design.widget.TabLayout)7 TextInputLayout (android.support.design.widget.TextInputLayout)7 Espresso.onView (android.support.test.espresso.Espresso.onView)7 FloatingActionButton (android.support.design.widget.FloatingActionButton)6 ViewGroup (android.view.ViewGroup)4 Matcher (org.hamcrest.Matcher)4 BaseMatcher (org.hamcrest.BaseMatcher)3 TabLayoutActions.setupWithViewPager (android.support.design.testutils.TabLayoutActions.setupWithViewPager)2 BottomNavigationView (android.support.design.widget.BottomNavigationView)2 CollapsingToolbarLayout (android.support.design.widget.CollapsingToolbarLayout)2 DrawerLayout (android.support.v4.widget.DrawerLayout)2 HorizontalScrollView (android.widget.HorizontalScrollView)2 TimeoutException (java.util.concurrent.TimeoutException)2 NoMatchingViewException (android.support.test.espresso.NoMatchingViewException)1