使用Espresso更新EditText [英] Updating an EditText with Espresso

查看:136
本文介绍了使用Espresso更新EditText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过以下方式更新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屋!

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