I am trying to automate few screen clicks and entries using monkeyrunner(using AndroidViewClient )
Whenever there is a edittext in the screen, the soft keyboard is popping up, and if I want to press a button though findViewById, (assuming that this particular button is behind the soft keyboard) fails. Instead of clicking this button, it clicks on some button in the soft keyboard. So as a work around I need to press back key through monkey runner, to hide the soft keyboard.
My question is how to determine whether soft keyboard is shown in the screen or not while running from monkeyrunner.
When I looked at the logcat, I see this following while showing up the soft keyboard
I/SurfaceFlinger( 2045): id=143(28) createSurf 0x4326743c (720x593),1 flag=0, InputMethod
and displays this while softkeyboard is removed
I/SurfaceFlinger( 2045): id=142 Removed InputMethod idx=4 MapSz=3
I/SurfaceFlinger( 2045): id=142 Removed InputMethod idx=-2 MapSz=3
If someone can provide an example of how to parse the adb logcat output from the monkeyrunner script, I can use that as a last option, if there is any suitable alternative solution found.
I found a way to overcome this problem. When I looked in the adb shell dumpsys input_method, I could see "mInputShown=true". So based on that I wrote the following function.
What you mentioned in your answer could be a great addition to AndroidViewClient and I'll try to incorporate it soon.
Anyway, there is a method of getting the same info, though in a more convoluted way:
Update on 11-FEB-15
Latest AndroidViewClient/culebra versions support
isKeyboardShown()
method. Use like this:LinkRefer
There is a way of doing what you want using the adb shell from monkeyrunner and it doesn't require a separate third-party library.
or
where
device
is the instance of MonkeyDevice for the attached device.I've found that applications that usually show a soft keyboard for input upon manual launch don't reliably show one when launched with monkeyrunner. If script logic depends on wehther the soft keyboard is showing or not, I use the above tests in the script to check if the soft keyboard is showing or not.
The following explanation includes some thinking about how to solve problems of this type.
returns a very large and detailed dump of all services running on the device. The
dumpsys
dump may be requested for a single service, in our case, the input services. That usage iswhich will return a much smaller dump which is just the current input method manager state. That dump will include all curent InputMethod instances, input method manager clients with general parameters for input method manager clients, input method client state, and input method server state. One set of general parameters for input method manager clients relates to whether an input method is shown (e.g. soft keyboard) and some parameters about whether the input method show was requested, explicitly requested or forced and whether it is being shown.
Whether the input method is shown is the one of interest since it is true when the soft keyboard is showing and false when the soft keyboard is not showing. That parameter's name is
and will look like
or
depending on whether the soft keyboard is showing or not.
The next step is making use of this information in a monkeyrunner script. The MonkeyDevice class includes a method for running an ADB shell command from within monkeyrunner's use of the bridge and which returns an object which is the return value to the ADB shell from executing the ADB shell command. Within a monkeyrunner script, that looks like
where
device
is the instance of the MonkeyDevice class for the attached device andshell_cmd_return_stuff
is variable holding all the shell command's output -- in this case the dump output. Finally, since we are looking for a specific parameter/value pair in the text and know what it looks like, we can use standard Jython to look for that string within the output returned without saving it in a variable and using the Jython stringin
boolean operatoror
depending on wehther we want to know if the soft keyboard is currently showing or not showing.
Enjoy!