Search in sources :

Example 1 with ScrollToAction

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

the class ViewInteraction method doPerform.

private void doPerform(final ViewAction viewAction) {
    checkNotNull(viewAction);
    final Matcher<? extends View> constraints = checkNotNull(viewAction.getConstraints());
    runSynchronouslyOnUiThread(new Runnable() {

        @Override
        public void run() {
            uiController.loopMainThreadUntilIdle();
            View targetView = viewFinder.getView();
            Log.i(TAG, String.format("Performing '%s' action on view %s", viewAction.getDescription(), viewMatcher));
            if (!constraints.matches(targetView)) {
                // TODO(user): update this to describeMismatch once hamcrest is updated to new
                StringDescription stringDescription = new StringDescription(new StringBuilder("Action will not be performed because the target view " + "does not match one or more of the following constraints:\n"));
                constraints.describeTo(stringDescription);
                stringDescription.appendText("\nTarget view: ").appendValue(HumanReadables.describe(targetView));
                if (viewAction instanceof ScrollToAction && isDescendantOfA(isAssignableFrom((AdapterView.class))).matches(targetView)) {
                    stringDescription.appendText("\nFurther Info: ScrollToAction on a view inside an AdapterView will not work. " + "Use Espresso.onData to load the view.");
                }
                throw new PerformException.Builder().withActionDescription(viewAction.getDescription()).withViewDescription(viewMatcher.toString()).withCause(new RuntimeException(stringDescription.toString())).build();
            } else {
                viewAction.perform(uiController, targetView);
            }
        }
    });
}
Also used : ScrollToAction(com.google.android.apps.common.testing.ui.espresso.action.ScrollToAction) StringDescription(org.hamcrest.StringDescription) AdapterView(android.widget.AdapterView) View(android.view.View) AdapterView(android.widget.AdapterView)

Aggregations

View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ScrollToAction (com.google.android.apps.common.testing.ui.espresso.action.ScrollToAction)1 StringDescription (org.hamcrest.StringDescription)1