使用Espresso更新EditText [英] Updating an EditText with Espresso
问题描述
我正在尝试通过以下方式更新EditText
作为Espresso测试的一部分:
I'm attempting to update an EditText
as part of an Espresso test with:
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
之前都在重新运行,而在第二个操作之前没有通过.尽管这是有道理的,但使我对如何使用Espresso更新EditText
感到有些困惑.我该怎么办?
By breaking down the test line I can see that this occurs after performing clearText()
, so I assume that the matchers are being re-run prior to each perform
and fail the prior to the second action. Although this makes sense, it leaves me somewhat confused as to how to update the EditText
using Espresso. How should I do this?
请注意,在这种情况下,我不能使用资源ID或类似资源,而必须使用上面显示的组合来标识正确的视图.
Note that I cannot use a resource ID or similar in this scenario and have to use the combination as shown above to identify the correct view.
推荐答案
您可以使用replaceText
方法.
onView(allOf(withClassName(endsWith("EditText")), withText(is("Test"))))
.perform(replaceText("Another test"));
这篇关于使用Espresso更新EditText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!