1

I am writing a series of automated tests for an android app using calabash-android and I need to be able to detect whether the android system keyboard is visible or not and (if possible) read some of the keys (i.e. if the return key says Done instead of Next or Enter). I know there is the keyboard_visible? commands for iOS but I have not been able to find anything similar for android.

Has anyone built their own functions to handle these instances?

Metomorphose
  • 434
  • 3
  • 14
  • I have not tried this but perhaps you can check the height of your views to see if keyboard is shown? – Lasse Jan 02 '15 at 06:46
  • I saw something about that. I was hoping for a more definite solution. – Metomorphose Jan 02 '15 at 14:19
  • Try to check for a element in keypad is displayed or not to make sure your device keypad is visible .. ex element_exists("* marked:'View_Name') . View_Name could be anything from your keypad – Mesh Jan 05 '15 at 09:52
  • That doesn't seem to work for me, although I don't know if there are special names for the keyboard components. – Metomorphose Jan 05 '15 at 14:15

2 Answers2

1

there is a way to take a dump of the screens current contents on android using a tool called uiautomator from the android SDK. You can then check this for whatever you need to. It's not the most elegant solution but it might just work. Have a look at this post.

Calabash handling "Complete action using" dialog

Community
  • 1
  • 1
alannichols
  • 1,496
  • 1
  • 10
  • 20
  • The uiautomator does not capture the components or properties of the keyboard. It only shows you a screen shot of it with all the components underneath it, which isn't very helpful when trying to find it in an automated test. – Metomorphose Jan 20 '15 at 16:52
  • @Metomorphose Hmm apologies, I really expected the keyboard to be included in the output with some options set that you could assert on. I've had a bit more of a look and this thread - http://stackoverflow.com/questions/5457486/is-there-a-way-to-tell-if-the-soft-keyboard-is-shown/24105062#24105062 has an answer that is working for me `adb shell dumpsys window InputMethod | grep "mHasSurface"` This should return true or false at the beginning (ish) of the return value. Not too sure about checking for specific buttons. – alannichols Jan 20 '15 at 17:15
0
windown_input_method = %x(adb -s #{ENV['ADB_DEVICE_ARG']} shell dumpsys window InputMethod | grep "mHasSurface")
windown_input_method.include?("isReadyForDisplay()=true")

This one returns true if keyboard is visible and false if not ENV['ADB_DEVICE_ARG'] is environmental variable holding the device id of your android device connected. If you always run on one device, simply

windown_input_method = %x(adb shell dumpsys window InputMethod | grep "mHasSurface")
windown_input_method.include?("isReadyForDisplay()=true")

will do

Clergyman
  • 281
  • 1
  • 3
  • 13