我正在尝试更新 EditText
作为 Espresso 测试的一部分:
onView(allOf(withClassName(endsWith("EditText")), withText(is("Test")))).perform(clearText())
.perform(click())
.perform(typeText("Another test"));
但是我收到以下错误:
com.google.android.apps.common.testing.ui.espresso.NoMatchingViewException: No views in hierarchy found matching: (with class name: a string ending with "EditText" and with text: is "Test")
通过分解测试线,我可以看到这是在执行 clearText()
之后发生的,所以我假设匹配器在每个 perform
之前重新运行并在第二个 Action 之前失败。虽然这是有道理的,但它让我对如何使用 Espresso 更新 EditText
感到有些困惑。我该怎么做?
请注意,在这种情况下,我不能使用资源 ID 或类似名称,必须使用如上所示的组合来识别正确的 View 。
最佳答案
您可以使用 replaceText
方法。
onView(allOf(withClassName(endsWith("EditText")), withText(is("Test"))))
.perform(replaceText("Another test"));
关于android - 使用 Espresso 更新 EditText,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23780857/