- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 Espresso,我希望能够单击 ExpandableListView(名为 CustomExpandableView)的特定子项。 listview 创建一组RelativeLayouts(名为MyContainer)。
理想情况下,我想单击 CustomExpandableView 中的特定 MyContainer。但是,我可以只点击第一个。
MyContainer 对象没有我可以引用的唯一 ID,但它们的子对象有,例如- “文本=此处的示例文本 1”
我尝试了几种不同的变体,使用 onData 传递类类型并尝试让 child 处于特定位置,但它只是不起作用。而且,我想避免获取对象并对其进行迭代,直到找到合适的 child 。
这是 View 层次结构的一部分供引用(我从层次结构中删除了不重要的信息):
+----->CustomExpandableView{}
|
+-------->线性布局{}
|
+------->TextView{}
|
+------->框架布局{}
|
+-------->面包屑 View {}
|
+--------->图像按钮{}
|
+--------->TextView{}
|
+-------->线性布局{}
|
+------->我的容器{}
|
+-------->ImageView{res-name=thumb, }
|
+-------->ImageView{res-name=divider}
|
+-------->TextView{res-name=label, text=Sample Text Here 1, input-type=0, ime-target=false}
|
+------->我的容器{}
|
+-------->ImageView{res-name=thumb}
|
+-------->ImageView{res-name=divider}
|
+-------->TextView{res-name=label text=Sample Text Here 2, input-type=0, ime-target=false}
|
最佳答案
当您尝试使用 onData
, Espresso 试图通过某些参数不查看 View ,但得到 Adapter
的 ListView
并在此适配器中搜索数据(通过调用 Adapter#getItem
)。
但是在 ExpandableListView
的情况下获取什么数据并不明显。
为此,Espresso 提供了 onData...().usingAdapterViewProtocol(AdapterViewProtocol)
.这个方法javadoc说:/**
* Use a different AdapterViewProtocol if the Adapter implementation does not
* satisfy the AdapterView contract like (@code ExpandableListView)
*/
这个 AdapterViewProtocol 接口(interface)看起来像:http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.0.0_r1/com/google/android/apps/common/testing/ui/espresso/action/AdapterViewProtocol.java .AdapterViewProtocol
的示例实现:https://stackoverflow.com/a/40282991/1282732
正确定义后,onData
将找到您搜索的项目 View 。之后,如果您需要对 child 执行操作或检查。你应该onData#onChildView
.
关于android-espresso - 在 Espresso 中单击 ListView 的特定子项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19695356/
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 4 年前。
正如您在 this travis.yml 中看到的那样文件,我的代码依赖于一些第三方库,我在构建项目之前将它们安装在远程系统上。 Travis 每次推送提交时都会下载并构建这些库,这可以避免吗?我的意
我是一名优秀的程序员,十分优秀!