简体   繁体   English

Espresso Instrumented 测试,层次结构中找不到与 RecycleView 匹配的视图

[英]Espresso Instrumented Test, No views in hierarchy found matching RecycleView

I have 3 items in Bottom Navigation:我在底部导航中有 3 个项目:

  1. Movie电影
  2. Tv Show电视节目
  3. Favorite (TabLayout with 2 items, default tab("Movie") & Second tab("Tv Show"))收藏夹(包含 2 个项目的选项卡布局,默认选项卡(“电影”)和第二个选项卡(“电视节目”))

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操作,这不是附加了onClickListenerView

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")TabViewperform(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.

相关问题 androidx.test.espresso.NoMatchingViewException:层次结构中没有找到匹配的视图 - androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching Android:Espresso,在层次结构中找不到匹配的视图 - Android: Espresso, No views in hierarchy found matching Android espresso 在层次结构中没有找到匹配的视图 - Android espresso No views in hierarchy found matching Android::android.support.test.espresso.NoMatchingViewException:在层次结构中没有找到匹配的视图 - Android::android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching Espresso:找不到与ID匹配的层次结构视图:android:id / home - Espresso:No views in hierarchy found matching with id: android:id/home Android 仪器测试未找到测试 - Android instrumented test no tests found Android:测试蓝牙启用意图(Espresso-Intents Instrumented Test) - Android: Test bluetooth enable intent (Espresso-Intents Instrumented Test) onWebView在层次结构中找不到匹配的视图:启用了JS的WebView - onWebView No views in hierarchy found matching: WebView with JS enabled 未找到浓缩咖啡测试 class - Espresso test class not found espresso onData匹配层次结构中的多个视图? - espresso onData matches multiple views in the hierarchy?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM