gpt4 book ai didi

java - Espresso Android 匹配父级中的 TextView

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:58:48 27 4
gpt4 key购买 nike

我有一个简单的线性布局,里面有两个 TextView 。线性布局有一个唯一的 id 但 textviews 没有。如何验证其中一个文本来自那些 TextView ?

我尝试了以下代码:

 onView(allOf(NavigationDrawerComponent.topSectionWrapper,
hasSibling(withClassName(Matchers.equalTo(TextView.class.getSimpleName())))))
.check(matches(withText(Data.fullUserName)));

不幸的是,它对我不起作用。我收到以下错误:

   android.support.test.espresso.NoMatchingViewException: No views in
hierarchy found matching

最佳答案

使用hasDescendant()

onView(withId(R.id.recycler_view)).check(matches(atPosition(0, hasDescendant(withText("Available")))));

关于java - Espresso Android 匹配父级中的 TextView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36852840/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com