Подтвердить что ты не робот

Espresso: Как проверить SwipeRefreshLayout?

Мое приложение перезагружает данные, когда прокрутка выполняется на SwipeRefreshLayout. Теперь я пытаюсь проверить это с помощью тестового набора для Android/Espresso следующим образом:

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

К сожалению, это не удается с помощью

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 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}"

Конечно, макет виден и ручка работает вручную, но я не уверен, что я делаю что-то неправильно? Макет охватывает весь экран, поэтому для эспрессо действительно должно быть сделано какое-то действие.

4b9b3361

Ответ 1

Спать над ним иногда помогает. Основная причина заключалась в том, что просматриваемый вид был всего лишь 89% видимым для пользователя, тогда как эспрессо-салфетки на внутреннем уровне требуют 90%. Таким образом, решение состоит в том, чтобы обернуть действие swipe в другое действие и переопределить эти ограничения вручную, например:

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);
        }
    };
}

Затем это можно вызвать так:

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