Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 'com.android.support.test.espresso:espresso-core:2.2.2' 

and tried to use this from android.support.test.espresso.action.ViewActions library:

ViewActions.closeSoftKeyboard(); 

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.

like image 334
getsadzeg Avatar asked Sep 19 '16 19:09

getsadzeg


2 Answers

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()

like image 150
Be_Negative Avatar answered Oct 06 '22 00:10

Be_Negative


You can implement this:

fun hideKeyboard() {     onView(ViewMatchers.isRoot()).perform(ViewActions.closeSoftKeyboard())   } 

After that only use this: paymentMethodPage.hideKeyboard()

like image 22
Tonny Tonny Avatar answered Oct 06 '22 02:10

Tonny Tonny