Espresso 单击 Textview 中的特定子字符串

Espresso click on specific substring inside a Textview

我有一个包含文本视图的布局,如下所示,它将在文本块中包含一些自动生成的链接。当用户单击链接时,会打开一个包含相关信息的 window。

但是,我完全不知道如何让 Espresso 点击链接。尝试了很多类似

的变体

matches(withText(containsString("45")))

但这要么不起作用,要么只点击文本框本身就可以制作浓缩咖啡,但它什么也没做。

有什么办法吗?在 Espresso 的限制范围内甚至可能吗?

您可以使用openLinkWithText(String linkText)

Returns an action that opens a link matching the given link text and uri matchers. The action is performed by invoking the link's onClick method (as opposed to actually issuing a click on the screen).

这是一个如何使用它的例子:

Espresso.onView(ViewMatchers
.withId(R.id.your_text_view_id))
.perform(ViewActions.openLinkWithText("45")); 

参考资料:espresso-recipes-for-android