gpt4 book ai didi

android - Espresso 测试不会写入 EditText

转载 作者:行者123 更新时间:2023-11-28 20:14:23 25 4
gpt4 key购买 nike

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()));

报这样的错误

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

所以我已经解决了,因为我的 EditText 在屏幕上可见,所以问题是我的 EditText 不是 "assignable from class: class android.widget.EditText" 所以我的问题是什么这意味着我的 EditText 不能从 android.widget.EditText 分配?以及如何使我的 EditText 可分配?

最佳答案

无论如何,您可以像这样写入编辑文本:

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

关于android - Espresso 测试不会写入 EditText,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37227888/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com