如何在 espresso UI 测试中检查动态文本

How to check dynamic text in espresso UI test

我需要执行简单的测试 - 文本视图匹配。 这很简单:

onView(withId(R.id.titleTextView)).check(matches(withText("Special Offer: First 3 Minutes Free")));

但是这部分 "First 3 Minutes Free" 在每次 activity 开始后随 "Get .99 for calls" 随机变化。

如何验证这两种情况? Espresso 中不允许使用运算符 ||...

withText 方法中使用 Hamcrest anyOf

onView(withId(R.id.titleTextView)).check(matches(withText(anyOf(is("Special Offer: First 3 Minutes Free"),is("Special Offer: Get .99 for calls")))));