FalconBot
FalconBot

Reputation: 429

Espresso test will not write to EditText

Espresso tests are being annoying because code like this

currentSailBoat = (SailBoat) boaterator.next();
ViewInteraction boatNameInteraction = onView(withId(R.id.txt_boat_name_edit));     
ViewInteraction boatNameInteraction = onView(withId(R.id.txt_boat_name_edit));
boatNameInteraction.perform(closeSoftKeyboard());
boatNameInteraction.perform(clearText());
boatNameInteraction.perform(typeText(currentSailBoat.getBoatName()));

gives an error like this

Runtime Exception
Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints: (is displayed on the screen to the user and is assignable from class: class android.widget.EditText) Target view: "TextView{id=2131624096, res-name=txt_boat_name_edit, visibility=VISIBLE, width=135, height=37, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=true, is-focusable=true, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=true, editor-info=[inputType=0x10001 imeOptions=0x8000005 privateImeOptions=null actionLabel=null actionId=0 initialSelStart=0 initialSelEnd=0 initialCapsMode=0x0 hintText=null label=null packageName=null fieldId=0 fieldName=null extras=null ], x=8.0, y=8.0, text=Boat Name, input-type=65537, ime-target=true, has-links=false}"

So I have worked out that since my EditText IS visible on the screen the problem is that my EditText is not "assignable from class: class android.widget.EditText" so my question is What does that mean that my EditText is not assignable from android.widget.EditText? and how do I make my EditText assignable?

Upvotes: 4

Views: 1745

Answers (1)

Stoica Mircea
Stoica Mircea

Reputation: 782

Anyway, you can write into the edit text like this:

boatNameInteraction.perform(replaceText(currentSailBoat.getBoatName()), closeSoftKeyboard());

Upvotes: 0

Related Questions