我正在使用Android Espresso,当找不到匹配项时,它将在打印视图层次结构时引发异常.当您运行AndroID测试或Espresso时,有没有一种方法可以动态获取这种视图层次结构
VIEw HIErarchy:+>DecorVIEw{ID=-1, visibility=VISIBLE, wIDth=480, height=800, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}|+->linearLayout{ID=-1, visibility=VISIBLE, wIDth=480, height=800, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}|+-->VIEwStub{ID=16909225, res-name=action_mode_bar_stub, visibility=GONE, wIDth=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}|+-->FrameLayout{ID=-1, visibility=VISIBLE, wIDth=480, height=764, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=36.0, child-count=1}|+--->ActionbarOverlayLayout{ID=2131427395, res-name=decor_content_parent, visibility=VISIBLE, wIDth=480, height=764, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}|
解决方法:
鉴于AndroID VIEw层次结构是树形结构,使用某种算法更容易遍历每个树形节点,您可以在https://developer.android.com/reference/android/support/test/espresso/util/TreeIterables.html处查看这些方法
它打印出异常跟踪的方式使用了一个名为广度FirstVIEwTraversaland的方法,它在类VIEwFinderImpl中打印出视图树
https://developer.android.com/reference/android/support/test/espresso/base/ViewFinderImpl.html
以上是内存溢出为你收集整理的如何在Android或Android Espresso中获取视图层次结构全部内容,希望文章能够帮你解决如何在Android或Android Espresso中获取视图层次结构所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)