android testing android-espresso

android - Espresso: ¿Cómo probar SwipeRefreshLayout?



testing android-espresso (1)

Mi aplicación vuelve a cargar los datos cuando se realiza un SwipeRefreshLayout hacia abajo en un SwipeRefreshLayout . Ahora trato de probar esto con Android Test Kit / Espresso de esta manera:

onView(withId(R.id.my_refresh_layout)).perform(swipeDown());

Desafortunadamente esto falla con

android.support.test.espresso.PerformException: Error performing ''fast swipe'' on view ''with id: my.app.package:id/my_refresh_layout''. ... Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints: at least 90 percent of the view''s area is displayed to the user. Target view: "SwipeRefreshLayout{id=2131689751, res-name=my_refresh_layout, visibility=VISIBLE, width=480, height=672, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}"

Por supuesto, el diseño es visible y el deslizamiento manual funciona, pero no estoy seguro de que esté haciendo algo mal. El diseño abarca toda la pantalla, por lo que realmente debería ser posible que Espresso haga algo al respecto.


Dormir sobre ella a veces ayuda. La razón subyacente fue que la vista a ser deslizada solo era 89% visible para el usuario, mientras que las acciones de barrido de Espresso demandan internamente el 90%. Entonces, la solución es envolver la acción de barrido en otra acción y anular estas restricciones a mano, como esto:

public static ViewAction withCustomConstraints(final ViewAction action, final Matcher<View> constraints) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return constraints; } @Override public String getDescription() { return action.getDescription(); } @Override public void perform(UiController uiController, View view) { action.perform(uiController, view); } }; }

Esto se puede llamar así:

onView(withId(R.id.my_refresh_layout)) .perform(withCustomConstraints(swipeDown(), isDisplayingAtLeast(85));