Search in sources :

Example 6 with ViewAction

use of androidx.test.espresso.ViewAction in project orgzly-android by orgzly.

the class EspressoUtils method setNumber.

public static ViewAction setNumber(final int num) {
    return new ViewAction() {

        @Override
        public void perform(UiController uiController, View view) {
            NumberPicker np = (NumberPicker) view;
            np.setValue(num);
        }

        @Override
        public String getDescription() {
            return "Set the passed number into the NumberPicker";
        }

        @Override
        public Matcher<View> getConstraints() {
            return ViewMatchers.isAssignableFrom(NumberPicker.class);
        }
    };
}
Also used : NumberPicker(android.widget.NumberPicker) ViewAction(androidx.test.espresso.ViewAction) UiController(androidx.test.espresso.UiController) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Espresso.onView(androidx.test.espresso.Espresso.onView) TextView(android.widget.TextView) ListView(android.widget.ListView)

Example 7 with ViewAction

use of androidx.test.espresso.ViewAction in project orgzly-android by orgzly.

the class EspressoUtils method closeSoftKeyboardWithDelay.

/**
 * Give keyboard time to close, to avoid java.lang.SecurityException
 * if hidden button is clicked next.
 */
static ViewAction closeSoftKeyboardWithDelay() {
    return new ViewAction() {

        /**
         * The delay time to allow the soft keyboard to dismiss.
         */
        private static final long KEYBOARD_DISMISSAL_DELAY_MILLIS = 1000L;

        /**
         * The real {@link CloseKeyboardAction} instance.
         */
        private final ViewAction mCloseSoftKeyboard = new CloseKeyboardAction();

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

        @Override
        public String getDescription() {
            return mCloseSoftKeyboard.getDescription();
        }

        @Override
        public void perform(final UiController uiController, final View view) {
            mCloseSoftKeyboard.perform(uiController, view);
            uiController.loopMainThreadForAtLeast(KEYBOARD_DISMISSAL_DELAY_MILLIS);
        }
    };
}
Also used : ViewAction(androidx.test.espresso.ViewAction) CloseKeyboardAction(androidx.test.espresso.action.CloseKeyboardAction) UiController(androidx.test.espresso.UiController) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Espresso.onView(androidx.test.espresso.Espresso.onView) TextView(android.widget.TextView) ListView(android.widget.ListView)

Example 8 with ViewAction

use of androidx.test.espresso.ViewAction in project orgzly-android by orgzly.

the class EspressoUtils method clickClickableSpan.

public static ViewAction clickClickableSpan(final CharSequence textToClick) {
    return new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return Matchers.instanceOf(TextView.class);
        }

        @Override
        public String getDescription() {
            return "Click text";
        }

        @Override
        public void perform(UiController uiController, View view) {
            TextView textView = (TextView) view;
            Spanned spannable = (Spanned) textView.getText();
            ClickableSpan clickable = null;
            for (ClickableSpan span : SpanUtils.getSpans(spannable, ClickableSpan.class)) {
                int start = spannable.getSpanStart(span);
                int end = spannable.getSpanEnd(span);
                CharSequence sequence = spannable.subSequence(start, end);
                if (sequence.toString().contains(textToClick)) {
                    clickable = span;
                    break;
                }
            }
            if (clickable != null) {
                clickable.onClick(textView);
            } else {
                throw new IllegalStateException("No clickable span found in " + spannable);
            }
        }
    };
}
Also used : ViewAction(androidx.test.espresso.ViewAction) UiController(androidx.test.espresso.UiController) TextView(android.widget.TextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Espresso.onView(androidx.test.espresso.Espresso.onView) TextView(android.widget.TextView) ListView(android.widget.ListView) Spanned(android.text.Spanned) ClickableSpan(android.text.style.ClickableSpan) ViewMatchers.withHint(androidx.test.espresso.matcher.ViewMatchers.withHint)

Example 9 with ViewAction

use of androidx.test.espresso.ViewAction in project collect by opendatakit.

the class FieldListUpdateTest method setRating.

public static ViewAction setRating(final float rating) {
    return new ViewAction() {

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

        @Override
        public String getDescription() {
            return "Custom view action to set rating on RatingBar";
        }

        @Override
        public void perform(UiController uiController, View view) {
            RatingBar ratingBar = (RatingBar) view;
            ratingBar.setRating(rating);
        }
    };
}
Also used : ViewAction(androidx.test.espresso.ViewAction) UiController(androidx.test.espresso.UiController) View(android.view.View) Espresso.onView(androidx.test.espresso.Espresso.onView) RatingBar(android.widget.RatingBar)

Example 10 with ViewAction

use of androidx.test.espresso.ViewAction in project Rocket by mozilla-tw.

the class RecyclerViewTestUtils method clickChildViewWithId.

public static ViewAction clickChildViewWithId(final int id) {
    return new ViewAction() {

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

        @Override
        public String getDescription() {
            return "Click on a child view with specified id.";
        }

        @Override
        public void perform(UiController uiController, View view) {
            View v = view.findViewById(id);
            v.performClick();
        }
    };
}
Also used : ViewAction(androidx.test.espresso.ViewAction) UiController(androidx.test.espresso.UiController) Espresso.onView(androidx.test.espresso.Espresso.onView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Aggregations

View (android.view.View)10 UiController (androidx.test.espresso.UiController)10 ViewAction (androidx.test.espresso.ViewAction)10 Espresso.onView (androidx.test.espresso.Espresso.onView)8 TextView (android.widget.TextView)4 RecyclerView (androidx.recyclerview.widget.RecyclerView)4 ListView (android.widget.ListView)3 TimeoutException (java.util.concurrent.TimeoutException)2 Matcher (org.hamcrest.Matcher)2 Activity (android.app.Activity)1 Spanned (android.text.Spanned)1 ClickableSpan (android.text.style.ClickableSpan)1 NumberPicker (android.widget.NumberPicker)1 RatingBar (android.widget.RatingBar)1 CloseKeyboardAction (androidx.test.espresso.action.CloseKeyboardAction)1 ViewMatchers.withHint (androidx.test.espresso.matcher.ViewMatchers.withHint)1 ConditionTimeoutException (org.awaitility.core.ConditionTimeoutException)1