【发布时间】:2025-12-25 03:40:11
【问题描述】:
我正在编写一个 espresso 测试,它检查在我以编程方式添加到 ListView 的 FooterView 中找不到 TextView。在 espresso 测试中找到 TextView 的唯一方法是等待 1 秒,然后再检查是否TextView 存在。
// checks if the list view contains an issue that has the text "Do" somewhere
onView(withId(R.id.listView)).check(matches(hasDescendant(withText(containsString("Do")))));
// swipes down to access the load older issues button
onView(allOf(withId(R.id.mainLayout))).perform(swipeUp());
// View listView = shelfActivity.getActivity().findViewById(R.id.listView_footer_textview); // returns the view, even when espresso tells that it does not exist
// Thread.sleep(1000); // need to wait in order to find the footerview of the list view
// check if the load older issues button is here
onView(allOf(withId(R.id.listView_footer_textview), isDisplayed())).check(matches(isDisplayed()));
FooterView 中的这个 TextView 实际上是存在的,如果我尝试使用正常的 findById() 方法获取它,我可以在同一个地方的测试中找到它,但是当我使用 espresso 检查它时找不到它。
所以我的问题是: 如果我想在 FooterView 中检查 TextView,我真的必须调用 Thread.sleep(1000) 才能通过测试吗?对我来说,espresso 的最大优势在于,我不必等待视图准备好,所以不存在自动执行此操作的 espresso 功能吗?
【问题讨论】:
标签: android listview android-espresso