如何在Android Espresso中将页面滚动到最底部?



我需要检查位于下面的按钮是否存在。为此,请滚动浏览页面

@Test
public void checkMoneyBackButton() throws Exception {
onView(withId(R.id.btnAuthLogin)).perform(click());
Thread.sleep(10000);
onView(withId(R.id.etSessionKey1)).perform(typeText("1234"));
closeSoftKeyboard();
SystemClock.sleep(45000);
ViewInteraction viewInteraction = Espresso.onView(withText("**** 0431"));
viewInteraction.perform(click());
Thread.sleep(3000);
onView(withId(R.id.cardContainer))
.perform(swipeUp());
onView(withId(R.id.statementMoneyBack)).check(matches(isDisplayed()));
}

但是使用此代码,我得到一个错误:

Error performing 'fast swipe' on view 'with id:...

Hacky 风格,但应该可以解决问题:

`` // Scroll down the view with for loop (as many times you need to iterate)
for(int i=0;i<=20;i++){
onView(withText("Use_here_any_text_from_the_view")).perform(swipeUp());
}
``

将咖啡师添加到您的浓缩咖啡中并使用此命令。咖啡师将帮助您在自动化中采取一些行动(特别是如果您的背景不像我那样是工程(。

scrollTo(R.id.far_away_widget);
scrollTo(R.string.text);
scrollTo("A widget with this text");

最新更新