get*_*zeg 15 testing android unit-testing android-espresso
我正在尝试测试应用程序,我需要隐藏键盘,因为我无法点击按钮.所以,我在build.gradle中添加了Espresso:
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
Run Code Online (Sandbox Code Playgroud)
并试图从android.support.test.espresso.action.ViewActions库中使用它:
ViewActions.closeSoftKeyboard();
Run Code Online (Sandbox Code Playgroud)
测试成功运行,但在我的布局中的EditText中键入一些文本后失败.键盘仍在那里,显示出来.
Be_*_*ive 35
ViewAction除非在它中使用,否则它本身不会做任何事情ViewInteraction.这意味着您需要使用之前的操作将其链接到perform()这样:onView()..perform(typeText(..), closeSoftKeyboard())或者使用类中的内置帮助程序Espresso:Espresso.closeSoftKeyboard()
小智 9
你可以这样实现:
fun hideKeyboard() {
onView(ViewMatchers.isRoot()).perform(ViewActions.closeSoftKeyboard())
}
Run Code Online (Sandbox Code Playgroud)
之后只使用这个:paymentMethodPage.hideKeyboard()