如何在 Espresso 中单击 RecyclerView 中的项目 [英] How to click on an item inside a RecyclerView in Espresso

查看:31
本文介绍了如何在 Espresso 中单击 RecyclerView 中的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 RecyclerView (R.id.recyclerView),其中每一行都有一个图像 (R.id.row_image) 和一个 TextView.我想点击第一行的图片.
我试过使用 onData(..) 但它似乎不起作用.

I have a RecyclerView (R.id.recyclerView) where each row has an image (R.id.row_image) and a TextView. I want to click on the image in the first row.
I've tried to use onData(..) but it doesn't seem to work.

推荐答案

使用 RecyclerViewActions

onView(withId(R.id.recyclerView))
    .perform(actionOnItemAtPosition(0, click()));

将此包含在您的 gradle 脚本中:

Include this in your gradle script:

dependencies {
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
    androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.0'
}

这篇关于如何在 Espresso 中单击 RecyclerView 中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆