Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
115 views
in Technique[技术] by (71.8m points)

android - Updating an EditText with 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"));

However I receive the following error:

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")

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?

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.

question from:https://stackoverflow.com/questions/23780857/updating-an-edittext-with-espresso

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use the replaceText method.

onView(allOf(withClassName(endsWith("EditText")), withText(is("Test"))))
    .perform(replaceText("Another test"));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...