Espresso scrollTo 不适用于托管 LinearLayout 的 ScrollView,该 LinearLayout 托管以编程方式生成的 LinearLayouts

Jam*_*mie 6 android android-espresso

我有一个 ScrollView,它托管一个 LinearLayout,然后在运行时托管一堆 LinearLayout(在之前的 LinearLayout 内)。

我想运行一个浓缩咖啡测试,该测试滚动到屏幕外的视图(滚动视图的下方),单击该视图即可进入下一个活动。运行 espresso 测试时,我尝试使用 ViewActions.scrollTo 来访问它,但它只是给了我一个资源未找到的异常。

但是,如果我在测试的单击部分之前放置一个断点,手动滚动以使视图可见,然后运行测试的“单击”部分,则测试运行得绝对正常。

有谁知道为什么滚动到不起作用?

我将 LinearLayouts id 设置为它们的数据字段之一,这样我就知道了 ID。

测试代码:

@Test
public void ensureScoreCorrect() {
    int manUtdView = Math.abs("Man Utd".hashCode());
    String score = getScore();
    Log.d("Hashcode:", " " + Math.abs("Man Utd".hashCode()));

    onView(withId(manUtdView)).perform(ViewActions.scrollTo());
    onView(withId(manUtdView)).perform(click());

    onView(withId(R.id.details_score))
            .check(matches(withText(score)));
}
Run Code Online (Sandbox Code Playgroud)

看法:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/all_matches_fragment"
    android:orientation="vertical"
    android:gravity="center"
    android:paddingBottom="90dp">

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

谢谢!