Android Espresso 在 GridView 上使用 onData() 匹配
Posted
技术标签:
【中文标题】Android Espresso 在 GridView 上使用 onData() 匹配【英文标题】:Android Espresso using onData() match on GridView 【发布时间】:2018-06-29 00:09:06 【问题描述】:我必须在 TextViewWithFont 中验证带有文本“congo”的元素
但是当我尝试时测试用例失败了
onData(withText("congo"))
.inAdapterView(withResourceName("gvTiles"))
.onChildView(allOf(withResourceName("mediaTileLayout"), withChild(withText("congo"))))
.onChildView(withResourceName("tvMediaName"))
.check(matches(isEnabled()));
它抛出的错误是
Caused by: java.lang.RuntimeException: No data found matching: with text: is "congo" contained values: <[Data: com.thisclicks.adr.db.models.Media@6f801f9 (class: com.thisclicks.adr.db.models.Media) token: 0, Data: com.thisclicks.adr.db.models.Media@7c8e53e (class: com.thisclicks.adr.db.models.Media) token: 1, Data: com.thisclicks.adr.db.models.Media@256af9f (class: com.thisclicks.adr.db.models.Media) token: 2, Data: com.thisclicks.adr.db.models.Media@c6568ec (class: com.thisclicks.adr.db.models.Media) token: 3, Data: com.thisclicks.adr.db.models.Media@fadc4b5 (class: com.thisclicks.adr.db.models.Media) token: 4, Data: com.thisclicks.adr.db.models.Media@7ea174a (class: com.thisclicks.adr.db.models.Media) token: 5, Data: com.thisclicks.adr.db.models.Media@f00a6bb (class: com.thisclicks.adr.db.models.Media) token: 6, Data: com.thisclicks.adr.db.models.Media@5b627d8 (class: com.thisclicks.adr.db.models.Media) token: 7, Data: com.thisclicks.adr.db.models.Media@7c2f731 (class: com.thisclicks.adr.db.models.Media) token: 8, Data: com.thisclicks.adr.db.models.Media@63a5e16 (class: com.thisclicks.adr.db.models.Media) token: 9, Data: com.thisclicks.adr.db.models.Media@a88f397 (class: com.thisclicks.adr.db.models.Media) token: 10, Data: com.thisclicks.adr.db.models.Media@451e984 (class: com.thisclicks.adr.db.models.Media) token: 11, Data: com.thisclicks.adr.db.models.Media@c1ed56d (class: com.thisclicks.adr.db.models.Media) token: 12]>
我不明白为什么会失败,因为有一个 TextViewWithFont 元素,其文本为“congo”。 GridView 包含 13 个元素,我认为错误消息中显示的数据是 GridView 中包含的这 13 个元素。
知道如何让它发挥作用吗?谢谢!
ViewHierarchy 是这样的(总结)
+>装饰视图... | +->ActionBarOverlayLayout... | ... | +--------->GridViewid=2131755465, res-name=gvTiles, visibility=VISIBLE ... ****匹配**** | +---------->RelativeLayoutid=2131755350, res-name=mediaTileLayout, visibility=VISIBLE ... | +----------->ImageView... | +----------->ImageView... | +----------->ImageView... | +----------->TextViewWithFontid=2131755352, res-name=tvMediaName, visibility=VISIBLE, width=78, height=80, has-focus=false, has-focusable=false, 有-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android .widget.RelativeLayout$LayoutParams@8ba38a0, tag=null, root-is-layout-requested=false, has-input-connection=false, x=20.0, y=121.0, text=congo, input-type=0, ime -目标=假,有链接=假 | ... | wid=2131755464, res-name=ivPlus, visibility=VISIBLE, width=37, height=37, 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=false, is-selected=false, layout-params=android.widget.RelativeLayout$LayoutParams@2be7593, tag=null, root-is-layout-requested=false, has-input-connection=false, x=130.0, y=0.0 | +---------->RelativeLayoutid=2131755350, res-name=mediaTileLayout, visibility=VISIBLE ... | +----------->ImageView... | +----------->ImageView... | +----------->ImageView... | +----------->TextViewWithFontid=2131755352, res-name=tvMediaName, visibility=VISIBLE, width=147, height=80, has-focus=false, has-focusable=false, 有-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android .widget.RelativeLayout$LayoutParams@7350832, tag=null, root-is-layout-requested=false, has-input-connection=false, x=20.0, y=121.0, text=时间表副本, input-type= 0, ime-target=false, has-links=false | ...
完整视图层次结构:
+>DecorViewid=-1, visibility=VISIBLE, width=768, height=1184, 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, layout-params=WM.LayoutParams(0,0)(fillxfill) ty= 1 fl=#1810100 pfl=0x20000 needsMenuKey=2,tag=null,root-is-layout-requested=false,has-input-connection=false,x=0.0,y=0.0,child-count=2 | +->ActionBarOverlayLayoutid=16909300, res-name=decor_content_parent, visibility=VISIBLE, width=768, height=1184, 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,layout-params=android.widget.FrameLayout$LayoutParams@fc546c,标签=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=3 | +-->FrameLayoutid=16908290, res-name=content, visibility=VISIBLE, width=768, height=1040, 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, layout-params=com.android.internal.widget.ActionBarOverlayLayout$ LayoutParams@a7baeca, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=144.0, child-count=1 | +--->DrawerLayoutid=2131755413, res-name=drawer_layout, visibility=VISIBLE, width=768, height=1040, has-focus=true, has-focusable=true, has-window-focus=true, is -clickable=false, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@7904b58 , tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2 | +---->FrameLayoutid=2131755414, res-name=content_frame, visibility=VISIBLE, width=768, height=1040, 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,layout-params=android.support.v4.widget。 DrawerLayout$LayoutParams@90ded96, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1 | +----->LinearLayoutid=2131755415, res-name=fragmentContainer, visibility=VISIBLE, width=768, height=1040, 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, layout-params=android.widget.FrameLayout$LayoutParams @a954aed, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2 | +------>ProgressBarid=2131755416, res-name=pbLoading, 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, layout-params=android.widget.LinearLayout$ LayoutParams@eb34d22, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0 | +------>RelativeLayoutid=-1, visibility=VISIBLE, width=768, height=1040, 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, layout-params=android.widget.LinearLayout$LayoutParams@f54555e, 标签=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2 | +------->RelativeLayoutid=2131755315, res-name=header, visibility=VISIBLE, width=768, height=100, 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=false, is-selected=false, layout-params=android.widget.RelativeLayout $LayoutParams@af116f8, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=5 | +-------->ImageViewid=2131755317, res-name=ivBack, visibility=VISIBLE, width=80, height=100, has-focus=false, has-focusable=false, has-window-焦点=true,is-clickable=true,is-enabled=true,is-focused=false,is-focusable=false,is-layout-requested=false,is-selected=false,layout-params=android.widget。 RelativeLayout$LayoutParams@97687d1, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0 | +-------->LinearLayoutid=-1, visibility=VISIBLE, width=124, height=82, has-focus=false, has-focusable=false, has-window-focus=true, 是-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android.widget.RelativeLayout$LayoutParams@49caaa4 , tag=null, root-is-layout-requested=false, has-input-connection=false, x=80.0, y=0.0, child-count=2 | +--------->RelativeLayoutid=2131755333, res-name=tvPrev, visibility=VISIBLE, width=107, height=33, 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=false, is-selected=false, layout-params=android.widget .LinearLayout$LayoutParams@a8cbbc2, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1 | +---------->TextViewid=2131755334, res-name=tvPrevOriginal, visibility=VISIBLE, width=77, height=27, has-focus=false, has-focusable=false, has-窗口焦点=真,可点击=真,已启用=真,已聚焦=假,可聚焦=假,已布局请求=假,已选=假,布局参数=安卓。 widget.RelativeLayout$LayoutParams@92d3dd3, tag=null, root-is-layout-requested=false, has-input-connection=false, x=30.0, y=6.0, text=APPLE > , input-type=0, ime -目标=假,有链接=假 | +--------->TextViewWithFontid=2131755316, res-name=tvHeaderText, visibility=VISIBLE, width=124, height=49, has-focus=false, has-focusable=false, has-window -focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android.widget .LinearLayout$LayoutParams@54bcd10, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=33.0, text=magma, input-type=0, ime-target =假,有链接=假 | +-------->ImageViewid=2131755426, res-name=linearFragmentContainer_btnPlus, visibility=VISIBLE, width=55, height=55, has-focus=false, has-focusable=false, has-window-焦点=true,is-clickable=true,is-enabled=true,is-focused=false,is-focusable=false,is-layout-requested=false,is-selected=false,layout-params=android.widget。 RelativeLayout$LayoutParams@4216009, tag=null, root-is-layout-requested=false, has-input-connection=false, x=693.0, y=22.0 | +-------->ButtonWithFontid=2131755427, res-name=linearFragmentContainer_btnRight, visibility=INVISIBLE, width=128, height=60, has-focus=false, has-focusable=false, has-window-焦点=true,is-clickable=true,is-enabled=true,is-focused=false,is-focusable=true,is-layout-requested=false,is-selected=false,layout-params=android.widget。 RelativeLayout$LayoutParams@d6ed20e, tag=null, root-is-layout-requested=false, has-input-connection=false, x=535.0, y=20.0, text=, input-type=0, ime-target=false , 有链接=假 | +-------->ButtonWithFontid=2131755429, res-name=linearFragmentContainer_btnLeft, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-焦点=true,is-clickable=true,is-enabled=true,is-focused=false,is-focusable=true,is-layout-requested=true,is-selected=false,layout-params=android.widget。 RelativeLayout$LayoutParams@103e42f, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=Clear, input-type=0, ime-target=假,有链接=假 | +------->LinearLayoutid=2131755428, res-name=linearFragmentContainer, visibility=VISIBLE, width=768, height=940, 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, layout-params=android.widget.RelativeLayout $LayoutParams@54a011a, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=100.0, child-count=2 | +-------->RelativeLayoutid=-1, visibility=VISIBLE, width=307, height=940, has-focus=false, has-focusable=true, has-window-focus=true, 是-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@6d80741 , tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=3 | +--------->RelativeLayoutid=2131755315, res-name=header, 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, layout-params=android.widget .RelativeLayout$LayoutParams@39141c3, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=5 | +---------->ImageViewid=2131755317, res-name=ivBack, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=false, has-窗口焦点=真,可点击=假,已启用=真,已聚焦=假,可聚焦=假,已布局请求=真,已选=假,布局参数=安卓。 widget.RelativeLayout$LayoutParams@6b49a40, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0 | +---------->LinearLayoutid=-1, visibility=VISIBLE, 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, layout-params=android.widget.RelativeLayout$LayoutParams @e691a6c, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=3 | +----------->RelativeLayoutid=2131755333, res-name=tvPrev, 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, layout-params=android .widget.LinearLayout$LayoutParams@734e4ca, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1 | +------------>TextViewid=2131755334, res-name=tvPrevOriginal, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, layout-params= android.widget.RelativeLayout$LayoutParams@d77263b, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=APPLE > , input-type=0 , ime-target=false, has-links=false | +----------->ButtonWithFontid=2131755346, res-name=btnSlideShow, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has -window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=true, is-selected=false, layout-params=android .widget.LinearLayout$LayoutParams@6037158, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=SlideShow, input-type=0, ime -目标=假,有链接=假 | +----------->TextViewWithFontid=2131755316, res-name=tvHeaderText, visibility=VISIBLE, 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, layout-params=android .widget.LinearLayout$LayoutParams@e1042b1, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=magma, input-type=0, ime -目标=假,有链接=假 | +---------->ImageViewid=2131755318, res-name=ivHeaderPlus, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=false, has-窗口焦点=真,可点击=真,已启用=真,已聚焦=假,可聚焦=假,已布局请求=真,已选=假,布局参数=安卓。 widget.RelativeLayout$LayoutParams@7248396, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0 | +---------->ButtonWithFontid=2131755319, res-name=btnRight, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-窗口焦点=真,可点击=真,已启用=真,已聚焦=假,可聚焦=真,已布局请求=真,已选=假,布局参数=安卓。 widget.RelativeLayout$LayoutParams@6a7eb17, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=, input-type=0, ime-target =假,有链接=假 | +---------->ButtonWithFontid=2131755335, res-name=btnLeft, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-窗口焦点=真,可点击=真,已启用=真,已聚焦=假,可聚焦=真,已布局请求=真,已选=假,布局参数=安卓。 widget.RelativeLayout$LayoutParams@9ea4b04, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=, input-type=0, ime-target =假,有链接=假 | +--------->GridViewid=2131755465, res-name=gvTiles, visibility=VISIBLE, width=247, height=880, has-focus=false, has-focusable=true, has-window -focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=android.widget .RelativeLayout$LayoutParams@91b96e9, tag=null, root-is-layout-requested=false, has-input-connection=false, x=30.0, y=30.0, child-count=4 ****匹配** ** | +---------->RelativeLayoutid=2131755350, res-name=mediaTileLayout, visibility=VISIBLE, width=167, height=217, has-focus=false, has-focusable=false, has-窗口焦点=真,可点击=假,已启用=真,已聚焦=假,可聚焦=假,已布局请求=假,已选=假,布局参数=安卓。 widget.AbsListView$LayoutParams@d787d34, tag=null, root-is-layout-requested=false, has-input-connection=false, x=40.0, y=0.0, child-count=11 | +----------->ImageViewid=2131755340, res-name=ivMediaTileThumbnail, desc=thumbnail, visibility=VISIBLE, width=167, height=217, has-focus=false, has-focusable =false, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, 布局-params=android.widget.RelativeLayout$LayoutParams@cab575d, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0 | +----------->ImageViewid=2131755351, res-name=ivGrayTitleBackground, visibility=VISIBLE, width=167, height=105, has-focus=false, has-focusable=false, 有-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android .widget.RelativeLayout$LayoutParams@880b8d2, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=112.0 | +----------->ImageViewid=2131755457, res-name=videoPlayButton, 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, layout-params=android .widget.RelativeLayout$LayoutParams@b8adda3, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0 | +----------->TextViewWithFontid=2131755352, res-name=tvMediaName, visibility=VISIBLE, width=78, height=80, has-focus=false, has-focusable=false, 有-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android .widget.RelativeLayout$LayoutParams@8ba38a0, tag=null, root-is-layout-requested=false, has-input-connection=false, x=20.0, y=121.0, text=congo, input-type=0, ime -目标=假,有链接=假 | +----------->RelativeLayoutid=2131755341, res-name=ivMediaTileIndicator, visibility=VISIBLE, width=100, height=100, 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=false, is-selected=false, layout-params=android .widget.RelativeLayout$LayoutParams@a63b0ff, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2 | +------------>ImageViewid=2131755342, res-name=highlight_indicator, visibility=VISIBLE, width=100, height=100, 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=false, is-selected=false, layout-params= android.widget.RelativeLayout$LayoutParams@9a3ecc, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0 | +------------>TextViewid=-1, visibility=VISIBLE, width=61, height=80, 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=false, is-selected=false, layout-params=android.widget.RelativeLayout $LayoutParams@e971515, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=NEW, input-type=0, ime-target=false , 有链接=假 | +----------->ImageViewid=2131755458, res-name=ivStreaming, 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, layout-params=android .widget.RelativeLayout$LayoutParams@1fe902a, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0 | +----------->ImageViewid=2131755459, res-name=ivStreamingOff_bg, 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, layout-params=android .widget.RelativeLayout$LayoutParams@3cc5e1b, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0 | +----------->LinearLayoutid=2131755460, res-name=ivStreamingOff, 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, layout-params=android .widget.RelativeLayout$LayoutParams@ecd84f6, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2 | +------------>ImageViewid=2131755461, res-name=wifi_off, visibility=VISIBLE, 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, layout-params= android.widget.LinearLayout$LayoutParams@848c0f7, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0 | +------------>TextViewid=2131755462, res-name=offline_label, visibility=VISIBLE, 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, layout-params= android.widget.LinearLayout$LayoutParams@7cf9b64, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=Unavailable offline, input-type=0 , ime-target=false, has-links=false | +----------->ImageViewid=2131755343, res-name=ivDelete, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has -window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, layout-params=android .widget.RelativeLayout$LayoutParams@815d1cd, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0 | +----------->ImageViewid=2131755463, res-name=ivMediaTileCorner, visibility=VISIBLE, width=80, height=80, has-focus=false, has-focusable=false, has -window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android .widget.RelativeLayout$LayoutParams@8c4fa82, tag=null, root-is-layout-requested=false, has-input-connection=false, x=87.0, y=0.0 | +----------->ImageViewid=2131755464, res-name=ivPlus, visibility=VISIBLE, width=37, height=37, 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=false, is-selected=false, layout-params=android .widget.RelativeLayout$LayoutParams@2be7593, tag=null, root-is-layout-requested=false, has-input-connection=false, x=130.0, y=0.0
【问题讨论】:
【参考方案1】:onData
不对视图层次结构进行操作,而是匹配适配器中的数据。正如堆栈跟踪所表明的那样,此数据是 Media
模型。
您必须编写一个与模型内容匹配的自定义TypeSafeMatcher
,这将有助于 espresso 在适配器中找到您感兴趣的 View 的位置。找到位置后,您可以使用onChildView()
和普通ViewMatchers
来验证正在显示的实际ItemView
。
【讨论】:
以上是关于Android Espresso 在 GridView 上使用 onData() 匹配的主要内容,如果未能解决你的问题,请参考以下文章
Android - Espresso:为每次测试重新创建活动
Android 自动化测试 Espresso篇:异步代码测试
运行 Espresso 测试时在 Android Studio 中找不到属性 android:forceQueryable
Android的报错提示:Failed to resolve: com.android.support.test.espresso:espresso-core:3.0.2