Search in sources :

Example 1 with ViewAction

use of android.support.test.espresso.ViewAction in project storymaker by StoryMaker.

the class Util method waitId.

public static ViewAction waitId(final int viewId, final long millis) {
    return new ViewAction() {

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

        @Override
        public String getDescription() {
            return "wait for a specific view with id <" + viewId + "> during " + millis + " millis.";
        }

        @Override
        public void perform(final UiController uiController, final View view) {
            uiController.loopMainThreadUntilIdle();
            final long startTime = System.currentTimeMillis();
            final long endTime = startTime + millis;
            final Matcher<View> viewMatcher = withId(viewId);
            do {
                for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
                    // found view with required ID
                    if (viewMatcher.matches(child)) {
                        return;
                    }
                }
                uiController.loopMainThreadForAtLeast(50);
            } while (System.currentTimeMillis() < endTime);
            // timeout happens
            throw new PerformException.Builder().withActionDescription(this.getDescription()).withViewDescription(HumanReadables.describe(view)).withCause(new TimeoutException()).build();
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) View(android.view.View) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with ViewAction

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

the class TextInputLayoutActions method setCounterMaxLength.

public static ViewAction setCounterMaxLength(final int maxLength) {
    return new ViewAction() {

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

        @Override
        public String getDescription() {
            return "Sets the counter max length";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            TextInputLayout layout = (TextInputLayout) view;
            layout.setCounterMaxLength(maxLength);
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) TextInputLayout(android.support.design.widget.TextInputLayout) View(android.view.View)

Example 3 with ViewAction

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

the class TextInputLayoutActions method setPasswordVisibilityToggleEnabled.

public static ViewAction setPasswordVisibilityToggleEnabled(final boolean enabled) {
    return new ViewAction() {

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

        @Override
        public String getDescription() {
            return "Sets the error";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            TextInputLayout layout = (TextInputLayout) view;
            layout.setPasswordVisibilityToggleEnabled(enabled);
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) TextInputLayout(android.support.design.widget.TextInputLayout) View(android.view.View)

Example 4 with ViewAction

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

the class TextInputLayoutActions method setTypeface.

public static ViewAction setTypeface(final Typeface typeface) {
    return new ViewAction() {

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

        @Override
        public String getDescription() {
            return "Sets the typeface";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            TextInputLayout layout = (TextInputLayout) view;
            layout.setTypeface(typeface);
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) TextInputLayout(android.support.design.widget.TextInputLayout) View(android.view.View)

Example 5 with ViewAction

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

the class TextInputLayoutActions method setError.

public static ViewAction setError(final CharSequence error) {
    return new ViewAction() {

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

        @Override
        public String getDescription() {
            return "Sets the error";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            TextInputLayout layout = (TextInputLayout) view;
            layout.setError(error);
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) TextInputLayout(android.support.design.widget.TextInputLayout) View(android.view.View)

Aggregations

ViewAction (android.support.test.espresso.ViewAction)64 View (android.view.View)60 UiController (android.support.test.espresso.UiController)55 NavigationView (android.support.design.widget.NavigationView)17 Espresso.onView (android.support.test.espresso.Espresso.onView)11 TextView (android.widget.TextView)11 Test (org.junit.Test)9 ViewPager (android.support.v4.view.ViewPager)8 TabLayout (android.support.design.widget.TabLayout)7 TextInputLayout (android.support.design.widget.TextInputLayout)7 FloatingActionButton (android.support.design.widget.FloatingActionButton)6 RecyclerView (android.support.v7.widget.RecyclerView)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 ViewInteraction (android.support.test.espresso.ViewInteraction)2 DrawerLayout (android.support.v4.widget.DrawerLayout)2