如何在 Espresso 上按下编辑器操作

How to presskey editor action on Espresso

如何使用 Espresso 按 Android 软键上的编辑器操作键?我试过了:

onView(withId(R.id.edToNumber)).perform(typeText("MDO158"),ViewActions.pressKey(KeyEvent.ACTION_UP), closeSoftKeyboard())

要从特定 EditText 的键盘单击 ActionDone button,您可以使用以下代码完成:

onView(withId(R.id.edToNumber)).perform(typeText("MDO158");
onView(withId(R.id.edToNumber)).perform(pressImeActionButton());

注:

pressImeActionButton()不是专门用来从键盘上点击ActionDone button,它点击键盘组成的任何ActionButtonActionDoneActionSearch , ActionNext, 等等

可选地,您可以使用以下代码关闭特定 EditText 的键盘,而无需单击 ActionDone 按钮:

onView(withId(R.id.edToNumber)).perform(typeText("MDO158");
onView(withId(R.id.edToNumber)).perform(closeSoftKeyboard());

您可以使用下面的代码

onView(withId(R.id.edToNumber))
        .perform(typeText("some"), pressImeActionButton());