androidmonkeyrunnerandroidviewclient

How to determine whether softkeyboard is shown on the screen - while using monkeyrunner


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.


Solution

  • 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:

    ...
    from com.dtmilano.android.viewclient import ViewClient
    
    vc = ViewClient(*ViewClient.connectToDeviceOrExit())
    view = vc.findViewByIdOrRaise('id/no_id/1')
    view.getXY() # getXY() calls __dumpsWindowsInformation()
    for w in view.windows:
        if view.windows[w].activity == 'InputMethod':
            print view.windows[w].visibility
    

    Update on 11-FEB-15

    Latest AndroidViewClient/culebra versions support isKeyboardShown() method. Use like this:

    #! /usr/bin/env python
    # -*- coding: utf-8 -*-
    '''
    Copyright (C) 2013-2014  Diego Torres Milano
    Created on 2015-02-11 by Culebra v10.0.8
                          __    __    __    __
                         /  \  /  \  /  \  /  \ 
    ____________________/  __\/  __\/  __\/  __\_____________________________
    ___________________/  /__/  /__/  /__/  /________________________________
                       | / \   / \   / \   / \   \___
                       |/   \_/   \_/   \_/   \    o \ 
                                               \_____/--<
    @author: Diego Torres Milano
    @author: Jennifer E. Swofford (ascii art snake)
    '''
    
    
    import re
    import sys
    import os
    
    
    try:
        sys.path.insert(0, os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
    except:
        pass
    
    from com.dtmilano.android.viewclient import ViewClient
    
    TAG = 'CULEBRA'
    
    _s = 5
    _v = '--verbose' in sys.argv
    
    
    kwargs1 = {'ignoreversioncheck': False, 'verbose': False, 'ignoresecuredevice': False}
    device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1)
    print "Is keyboard shown:", device.isKeyboardShown()