gpt4 book ai didi

java - Android Espresso 无法输入 TYPE_TEXT_VARIATION_NORMAL?

转载 作者:行者123 更新时间:2023-11-30 10:31:49 24 4
gpt4 key购买 nike

我的 Android 应用程序中有一个 TextInputEditText View ,我正在以编程方式(通过 Anko 和 Kotlin)设置它,如下所示:

            textInputEditText {
id = R.id.text_input_id
inputType = EditorInfo.TYPE_TEXT_VARIATION_NORMAL
hint = resources.getText(R.string.text_hint)
}

然后在 Espresso 测试中我调用这一行:

onView(withId(R.id.text_input_id)).perform(typeText(textToType))

失败并出现此错误:

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 (supports input methods or is assignable from class: class android.widget.SearchView))
Target view: "TextInputEditText{id=2131623954, res-name=text_input_id, visibility=VISIBLE, width=862, height=118, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=, input-type=0, ime-target=false, has-links=false}"

我发现如果我从这里切换它:

/**
* Default variation of {@link #TYPE_CLASS_TEXT}: plain old normal text.
*/
public static final int TYPE_TEXT_VARIATION_NORMAL = 0x00000000;

对此:

/**
* Variation of {@link #TYPE_CLASS_TEXT}: entering a password, which should
* be visible to the user.
*/
public static final int TYPE_TEXT_VARIATION_VISIBLE_PASSWORD = 0x00000090;

它突然神奇地起作用了!但这没有多大意义。普通文本听起来很合适,直到 Espresso 在我面前爆炸。这是 Espresso 的错误,还是我不理解的地方?

最佳答案

我的猜测是这发生在 typeText 调用中。请参阅 TypeTextAction.getConstraints() 中的约束列表。逻辑本质上是:

isDisplayed() &&
hasFocus() &&
( supportsInputMethods() || isAssignableFrom(SearchView.class) )

我的第一个猜测是它没有通过 supportsInputMethods() 约束。您可以在 ViewMatchers.supportsInputMethods() -> matchesSafely() 中放置一个断点并自行查看。

关于java - Android Espresso 无法输入 TYPE_TEXT_VARIATION_NORMAL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42983457/

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