Android 如何使用浓缩咖啡检查屏幕外的视图可见性?
根据我在Espresso备忘单中看到的内容,有两种方法可以检查视图的可见性,Android 如何使用浓缩咖啡检查屏幕外的视图可见性?,android,android-espresso,Android,Android Espresso,根据我在Espresso备忘单中看到的内容,有两种方法可以检查视图的可见性,isDisplayed()和iscompletlydisplayed() 我的主屏幕上有滑动布局,其中有几个视图。我正在通过以下命令检查其中一个: onView(withId(R.id.payment_btn)).check(matches(isDisplayed())); 但是,测试将停止并显示以下错误: android.support.test.espresso.base.DefaultFailureHandler
isDisplayed()
和iscompletlydisplayed()
我的主屏幕上有滑动布局,其中有几个视图。我正在通过以下命令检查其中一个:
onView(withId(R.id.payment_btn)).check(matches(isDisplayed()));
但是,测试将停止并显示以下错误:
android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'is displayed on the screen to the user' doesn't match the selected view.
Expected: is displayed on the screen to the user
然后我想,由于视图不可见,我可以通过以下测试来测试它:
onView(withId(R.id.payment_btn)).check(doesNotExist());
但是,测试停止并显示以下消息:
android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: View is present in the hierarchy:
Expected: is <false>
Got: <true>
层次结构中存在android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError:View:
预期:是吗
得到了:
那么,如何检查屏幕外视图的可见性呢?当视图位于屏幕外时,它不会显示,但仍存在于视图层次结构中。要检查视图是否未显示在屏幕上,请使用:
onView(带id(R.id.payment_btn))。检查(匹配项(不匹配(isDisplayed()))代码>
如果要检查是否显示,必须滚动/滑动到视图,使其可见。谢谢,我刚刚找到它并想回答:)很好,谢谢您的解释。。。