Search in sources :

Example 21 with UiController

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

the class FloatingActionButtonActions method hideThenShow.

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

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

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

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            FloatingActionButton fab = (FloatingActionButton) view;
            fab.hide();
            fab.show();
            uiController.loopMainThreadForAtLeast(animDuration + 100);
        }
    };
}
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 22 with UiController

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

the class FloatingActionButtonActions method setImageResource.

public static ViewAction setImageResource(@DrawableRes final int resId) {
    return new ViewAction() {

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

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

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            final FloatingActionButton fab = (FloatingActionButton) view;
            fab.setImageResource(resId);
            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)

Example 23 with UiController

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

the class NavigationViewActions method setCheckedItem.

/** Sets checked item on the navigation view. */
public static ViewAction setCheckedItem(@IdRes final int id) {
    return new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return isDisplayed();
        }

        @Override
        public String getDescription() {
            return "Set checked item";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            NavigationView navigationView = (NavigationView) view;
            navigationView.setCheckedItem(id);
            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) View(android.view.View)

Example 24 with UiController

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

the class CoordinatorSnackbarWithFabTest method getSnackbarLocationOnScreen.

/** Returns the location of our snackbar on the screen. */
private static int[] getSnackbarLocationOnScreen() {
    final int[] location = new int[2];
    onView(isAssignableFrom(Snackbar.SnackbarLayout.class)).perform(new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return isEnabled();
        }

        @Override
        public String getDescription() {
            return "Snackbar matcher";
        }

        @Override
        public void perform(UiController uiController, View view) {
            view.getLocationOnScreen(location);
        }
    });
    return location;
}
Also used : ViewAction(android.support.test.espresso.ViewAction) Matcher(org.hamcrest.Matcher) UiController(android.support.test.espresso.UiController) AppCompatTextView(android.support.v7.widget.AppCompatTextView) Espresso.onView(android.support.test.espresso.Espresso.onView) View(android.view.View)

Example 25 with UiController

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

the class TabLayoutWithViewPagerTest method addItemToPager.

private static <Q> ViewAction addItemToPager(final String title, final Q content) {
    return new ViewAction() {

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

        @Override
        public String getDescription() {
            return "Add item and notify on content change";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            final ViewPager viewPager = (ViewPager) view;
            // no way to avoid this cast
            @SuppressWarnings("unchecked") final BasePagerAdapter<Q> viewPagerAdapter = (BasePagerAdapter<Q>) viewPager.getAdapter();
            viewPagerAdapter.add(title, content);
            viewPagerAdapter.notifyDataSetChanged();
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) HorizontalScrollView(android.widget.HorizontalScrollView) View(android.view.View) TextView(android.widget.TextView) Espresso.onView(android.support.test.espresso.Espresso.onView) ViewPager(android.support.v4.view.ViewPager) TabLayoutActions.setupWithViewPager(android.support.design.testutils.TabLayoutActions.setupWithViewPager)

Aggregations

UiController (android.support.test.espresso.UiController)57 View (android.view.View)57 ViewAction (android.support.test.espresso.ViewAction)56 NavigationView (android.support.design.widget.NavigationView)18 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 NotFoundException (android.content.res.Resources.NotFoundException)1