我需要向下滚动浏览我的NestedScrollView以使用Espresso测试我的xml文件,但是我收到错误消息:"在视图上执行'滚动到'时出错",ID为:
其他几个帖子似乎也有类似的问题.
我遵循了以下说明:Android espresso NestedScrollView,如何滚动到底部
现在我得到前面提到的错误,并发现这篇文章:尝试滚动查看,但不显示视图
我的NestedScrollView中没有填充 - 我甚至尝试从XML中删除填充,用于测试目的,但它没有任何区别.
这是我的测试(到目前为止它不应该做任何事情,但向下滚动):
@Test
public void testScrollDownAbilityOfDetailsScrollView(){
goToSpecificItemOnStream(streamItemWithOneImage);
onView(withId(R.id.end_of_details))
.perform(ScrollToAction.betterScrollTo());
}
Run Code Online (Sandbox Code Playgroud)
它使用自定义的Scroll To Action类:
public final class ScrollToAction implements ViewAction {
private static final String TAG = ScrollToAction.class.getSimpleName();
@SuppressWarnings("unchecked")
@Override
public Matcher<View> getConstraints() {
return allOf(withEffectiveVisibility(Visibility.VISIBLE), isDescendantOfA(anyOf(
isAssignableFrom(ScrollView.class), isAssignableFrom(HorizontalScrollView.class), isAssignableFrom(NestedScrollView.class))));
}
@Override
public void perform(UiController uiController, View view) {
if (isDisplayingAtLeast(80).matches(view)) {
Log.i(TAG, "View is already displayed. Returning.");
return;
}
Rect rect = new Rect();
view.getDrawingRect(rect);
if (!view.requestRectangleOnScreen(rect, true /* immediate …Run Code Online (Sandbox Code Playgroud)