android - Android:布局的任何视图上的 androidx.test.espresso.AmbiguousViewMatcherException
问题描述
在我的浓缩咖啡测试用例检查
onView(withId(R.id.myRecyclerView)).check(matches(isDisplayed()))
给出异常 androidx.test.espresso.AmbiguousViewMatcherException: 'with id: com.xxx.xxx.debug:id/myRecyclerView' 匹配层次结构中的多个视图。
如何在层次结构中有多个 recyclerview 实例。
布局结构为:
`<androidx.core.widget.NestedScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:fillViewport="false"
android:scrollbars="none"
android:visibility="condition here"
app:layout_constraintBottom_toTopOf="@id/bottomButtonsContainer"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<FrameLayout
android:id="@+id/contents"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/lead_details_spacing"
android:orientation="vertical"
android:paddingBottom="@dimen/lead_details_spacing">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/myRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="never"
android:contentDescription="test"
android:visibility="condition"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"></androidx.recyclerview.widget.RecyclerView>
</FrameLayout>
</androidx.core.widget.NestedScrollView>
如何解决此异常?
编辑
我浏览了登录详细信息。我看到的是在视图层次结构下
Problem views are marked with ‘****MATCHES****’ below. View Hierarchy:
整个布局来了两次。
流程:主页 -> 选项卡活动 -> tab2 上面提到的带有 recyclerview 的布局 -> 单击此布局的按钮会转到另一个活动 X -> 返回 tab2 -> 使用 espresso 验证 recyclerview 的内容
当我第一次登陆 tab2 片段时,我可以单击按钮。但是当我从活动 X 回到 tab2 并尝试再次单击时,我得到了相同的 AmbiguousViewMatcher 异常。所以整个布局不知何故被复制了。我尝试检查布局,但没有看到任何重复项。关于可能出错的任何指示?
解决方案
推荐阅读
- python - Python插入Json并使用pymongo更新mongodb
- deployment - 将 Nextjs 项目部署到 FTP
- c# - DbSet 不包含 SaveChanges 的定义
- intellij-idea - 类型参数“BreakBlock”不能直接实例化(Minecraft Spigot 插件)
- javascript - 数组 A [N] 包含自然数。求给定 K 的倍数的元素之和
- flutter - 将本地存储图像的路径传递给 social_share 插件
- python - 我的 Dice 系数在训练的早期和波动阶段“超调”的解释是什么
- python - Web Scraping Selenium and Beautiful soup - 无法导出到 csv 文件
- python - 如何从循环中更新函数中的变量?
- paypal - Paypal // Wix // Quickbooks