getsadzeg getsadzeg - 1 year ago 71
Android Question

I can't make ViewActions.closeSoftKeyboard() work in Espresso 2.2.2

I'm trying to test an app and I require to hide the keyboard, because I cannot click button because of it. So, I added Espresso in build.gradle:

androidTestCompile ''

and tried to use this from


Test runs successfully, but fails after typing some text in EditText in my layout. And keyboard is still there, showing.

P.S. I realized it was keyboard's fault after reading this answer.

Answer Source

ViewAction on its own does not do anything unless it is used in the ViewInteraction. That means that you need to either chain it with your previous action in perform() like this: onView()..perform(typeText(..), closeSoftKeyboard()) or use a built-in helper which is in Espresso class like this: Espresso.closeSoftKeyboard()

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download