测试时OnEditorActionListener不起作用

时间:2019-05-22 17:30:45

标签: android android-espresso

我在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的常见问题吗?

1 个答案:

答案 0 :(得分:1)

closeSoftKeyboard():在我看来,这只是隐藏键盘。 尝试使用ViewActions中的一种不同方法。

从文档中

  • ViewActions#closeSoftKeyboard():返回关闭软键盘的操作。

  • ViewActions#pressImeActionButton():返回在IME(输入法编辑器)上按下当前操作按钮(下一步,完成,搜索等)的操作。

我将赌注押在pressImeActionButton()(未经测试的场外)上

相关问题