如何在Espresso上按编辑器操作

时间:2018-10-08 02:20:28

标签: android android-espresso

如何使用Espresso在Android软键上按“编辑器操作”键?我尝试过:

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

enter image description here

2 个答案:

答案 0 :(得分:0)

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

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

注意:

pressImeActionButton()(不是专门用于单击键盘上的ActionDone button,它会单击键盘上的任何ActionButton,例如ActionDoneActionSearch,{ {1}}等

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

ActionNext

答案 1 :(得分:0)

您可以使用以下代码

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