测试时 OnEditorActionListener 不工作
OnEditorActionListener not working when testing
我在 EditText 上使用 OnEditorActionListener
scoreboardNameEdit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
...
}
});
在开发过程中和手动测试时,一切都运行良好。现在我想用 Android Espresso
测试一下
onView(withId(tv_id)).perform(typeText(to_type)).perform(closeSoftKeyboard());
并且不会调用 OnEditorActionListener
这是 Android Espresso 的常见问题吗?
closeSoftKeyboard()
:在我看来这只是隐藏了键盘。
尝试使用 ViewActions.
中的不同方法之一
来自文档:
ViewActions#closeSoftKeyboard()
: Returns关闭软键盘的动作。
ViewActions#pressImeActionButton()
: Returns 按下 IME(输入法编辑器)上的当前操作按钮(下一步、完成、搜索等)的操作。
我会把赌注押在 pressImeActionButton()
(未经测试的场外)
我在 EditText 上使用 OnEditorActionListener
scoreboardNameEdit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
...
}
});
在开发过程中和手动测试时,一切都运行良好。现在我想用 Android Espresso
测试一下onView(withId(tv_id)).perform(typeText(to_type)).perform(closeSoftKeyboard());
并且不会调用 OnEditorActionListener
这是 Android Espresso 的常见问题吗?
closeSoftKeyboard()
:在我看来这只是隐藏了键盘。
尝试使用 ViewActions.
来自文档:
ViewActions#closeSoftKeyboard()
: Returns关闭软键盘的动作。ViewActions#pressImeActionButton()
: Returns 按下 IME(输入法编辑器)上的当前操作按钮(下一步、完成、搜索等)的操作。
我会把赌注押在 pressImeActionButton()
(未经测试的场外)