Espresso测试令人讨厌,因为这样的代码
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()));
给出了这样的错误
运行时异常
引发者:java.lang.RuntimeException:由于目标视图与以下一个或多个约束不匹配,因此不会执行操作: (在屏幕上显示给用户,可从类中分配:class android.widget.EditText ) 目标视图:“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-点击= 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}“
所以我得出结论,因为我的EditText在屏幕上可见,问题是我的EditText不是“可从类中分配:class android.widget.EditText”所以我的问题是什么这意味着我的EditText不能从android.widget.EditText分配?以及如何指定EditText?
答案 0 :(得分:0)
无论如何,您可以像这样将其写入编辑文本:
boatNameInteraction.perform(replaceText(currentSailBoat.getBoatName()), closeSoftKeyboard());