gpt4 book ai didi

android - 使用 Android Espresso 在层次结构中查找 View

转载 作者:太空宇宙 更新时间:2023-11-03 11:47:18 26 4
gpt4 key购买 nike

我有一个带有自定义 View 的仪表板。

我想测试一旦数据可用,它就会正确显示在各种 TextView 中。

我的问题是:如何选择属于层次结构的各种 TextView。

示例:如何获取current_month > sales > value view

我只知道如何处理单个层次结构级别,但这对这里没有帮助:

onView(
allOf(withId(R.id.value),
isDescendantOfA(withId(R.id.current_month))))

层次结构如下:

+- RelativeLayout
|
|___+ CustomCardView (id = current_month)
| |
| |___+ CustomValueView (id = sales)
| | |
| | |___+ TextView (id = value)
| | |
| | |___+ TextView (id = unit)
| |
| |___+ CustomValueView (id = earnings)
| |
| |___+ TextView (id = value)
| |
| |___+ TextView (id = unit)
|
|___+ CustomCardView (id = last_month)
| |
| |___+ CustomValueView (id = sales)
| | |
| | |___+ TextView (id = value)
| | |
| | |___+ TextView (id = unit)
| |
| |___+ CustomValueView (id = earnings)
| |
| |___+ TextView (id = value)
| |
| |___+ TextView (id = unit)
|
|___+ CustomCardView (id = all_time)
|
|___+ CustomValueView (id = sales)
| |
| |___+ TextView (id = value)
| |
| |___+ TextView (id = unit)
|
|___+ CustomValueView (id = earnings)
|
|___+ TextView (id = value)
|
|___+ TextView (id = unit)

最佳答案

好的。看起来很简单。

    onView(allOf(withId(R.id.value),
isDescendantOfA(allOf(withId(R.id.sales),
isDescendantOfA(withId(R.id.current_month))))))

这是最好的方法吗?

关于android - 使用 Android Espresso 在层次结构中查找 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42094681/

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