浓缩咖啡 - withEffectiveVisibility vs isDisplayed [英] Espresso - withEffectiveVisibility vs isDisplayed

查看:45
本文介绍了浓缩咖啡 - withEffectiveVisibility vs isDisplayed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

isDisplayedwithEffectiveVisibility 有什么区别?

onView(withText("Much Dagger")).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));


onView(withText("Much Dagger")).check(matches(ViewMatchers.isDisplayed());

推荐答案

根据文档

返回匹配 {@link View} 的匹配器,该 {@link View} 具有设置为给定值的有效"可见性.有效的可见性不仅考虑视图的可见性值,还考虑其祖先的可见性值.在 View.VISIBLE 的情况下,这意味着视图及其所有祖先都具有可见性=VISIBLE.在 GONE 和 INVISIBLE 的情况下,情况正好相反 - 任何 GONE 或 INVISIBLE 父级都会使其所有子级都具有有效的可见性.

Returns a matcher that matches {@link View}s that have "effective" visibility set to the given value. Effective visibility takes into account not only the view's visibility value, but also that of its ancestors. In case of View.VISIBLE, this means that the view and all of its ancestors have visibility=VISIBLE. In case of GONE and INVISIBLE, it's the opposite - any GONE or INVISIBLE parent will make all of its children have their effective visibility.

与名称所暗示的相反,视图可见性并不能直接转化为视图是否显示在屏幕上(为此使用 isDisplayed()).例如,视图及其所有祖先可以具有可见性=VISIBLE,但视图可能需要滚动到才能真正对用户可见.除非您在测试中专门针对可见性值,否则请使用 isDisplayed.

Contrary to what the name may imply, view visibility does not directly translate into whether the view is displayed on screen (use isDisplayed() for that). For example, the view and all of its ancestors can have visibility=VISIBLE, but the view may need to be scrolled to in order to be actually visible to the user. Unless you're specifically targeting the visibility value with your test, use isDisplayed.

因此,如果用于验证视图是否可见,请使用 isDisplayed() 但用于其他验证,如果不可见并消失,请使用 withEffectiveVisibilty()

So if using for verifying if a view is visible use isDisplayed() but for other verification incase if invisible and gone use withEffectiveVisibilty()

这篇关于浓缩咖啡 - withEffectiveVisibility vs isDisplayed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆