如何在Espresso中按下按键编辑器操作

4
如何使用Espresso在Android软键盘上按Editor Action键?我尝试过:
onView(withId(R.id.edToNumber)).perform(typeText("MDO158"),ViewActions.pressKey(KeyEvent.ACTION_UP), closeSoftKeyboard())

2个回答

10

要从特定的EditText键盘上点击,你可以使用以下代码:

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

注意:

pressImeActionButton() 方法不仅用于点击键盘上的 ActionDone按钮,它可以点击键盘中包含的任何 ActionButton,例如 ActionSearch ActionNext等。

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

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

2

您可以使用以下代码

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接