我正在尝试构建一个测试,以使用 Espresso 验证我的 PreferenceScreen
View 。我要单击的文本位于底部。那么如何使用 Espresso 在 PreferenceScreen
中向下滚动?
我试过这段代码,但没有用:
onData(allOf(is(instanceOf(String.class)), is("Notifications"))).perform(click());
最佳答案
这曾经有效:
onData(PreferenceMatchers.withTitleText("Notifications")).perform(click());
但是现在你可以使用RecyclerViewActions
:
onView(withId(androidx.preference.R.id.recycler_view))
.perform(RecyclerViewActions.actionOnItem(hasDescendant(withText("Notifications")),
click()));
关于testing - 如何滚动 PreferenceScreen?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38023269/