I want to test keyboard visibility when an activity calls onCreate() and onResume().
How can i test whether or not the keyboard is shown using espresso?
I know, that the question is old enough, but it doesn't have any accepted answer though. In our UI tests we use this method, which uses some shell commands:
/**
* This method works like a charm
*
* SAMPLE CMD OUTPUT:
* mShowRequested=true mShowExplicitlyRequested=true mShowForced=false mInputShown=true
*/
fun isKeyboardOpenedShellCheck(): Boolean {
val checkKeyboardCmd = "dumpsys input_method | grep mInputShown"
try {
return UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
.executeShellCommand(checkKeyboardCmd).contains("mInputShown=true")
} catch (e: IOException) {
throw RuntimeException("Keyboard check failed", e)
}
}
Hope, it'll be useful for someone