[英]Espresso Instrumented Test, No views in hierarchy found matching RecycleView
I have 3 items in Bottom Navigation:我在底部导航中有 3 个项目:
On the default tab (Favorite Movie) was successful.在默认选项卡(最喜欢的电影)上是成功的。
onView(withId(R.id.nav_favorite)).perform(click())
onView(allOf(withId(R.id.rv_favorite_film), isDisplayed())).check(matches(isDisplayed())) //SUCCESS
I have a problem in Favorite Item -> Second tab Tv Show when testing:测试时我在最喜欢的项目 - > 第二个选项卡电视节目中有问题:
onView(withId(R.id.nav_favorite)).perform(click())
onView(allOf(withText("Tv Show"), isDescendantOfA(withId(R.id.tabs)))).perform(click())
onView(allOf(withId(R.id.rv_favorite_tvshow), isDisplayed())).check(matches(isDisplayed())) //ERROR
How to fix it?.如何解决? Thanks
谢谢
I think you're performing
a click
action on a TextView
which is not the View
that has the onClickListener
attached to it.我认为您正在对
TextView
performing
click
操作,这不是附加了onClickListener
的View
。
Within TabLayout
you have a hierarchy of TabViews
with TextViews
nested within them.在
TabLayout
,您有一个TabViews
的层次结构,其中嵌套了TextViews
。 The thing that has an onClickListener
is not the TextView
(matching allOf(withText("Tv Show"), isDescendantOfA(withId(R.id.tabs)))
) but the TabView
.具有
onClickListener
的东西不是TextView
(匹配allOf(withText("Tv Show"), isDescendantOfA(withId(R.id.tabs)))
)而是TabView
。
So you should perform(click())
on a TabView
that has a child withText("Tv Show")
.因此,您应该在具有子
withText("Tv Show")
的TabView
上perform(click())
)。
I don't remember the exact syntax of Espresso, but if you tried using my Cortado library () it should be:我不记得 Espresso 的确切语法,但如果你尝试使用我的 Cortado 库(),它应该是:
Cortado.onView().isAssignableFrom(TabView::class.java).and().hasDescendant(withText("Tv Show")).perform().click()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.