Search code examples
monkeyrunnerlong-press

how to open recent app list panel via Monkeyrunner


for automation testing using monkeyrunner, i want to launch a app from recent app list panel, while the panel cannot be opened after long press HOME key via monkeyrunner command.

device.press('KEYCODE_HOME',MonkeyDevice.DOWN)
Monkeyrunner.sleep(5)
device.press('KEYCODE_HOME',MonkeyDevice.UP)

with the above code, the press is acted as a short press. And the panel can be opened after long pressing HOME key manually. is there some solution for this issue?

Thanks.


Solution

  • You can use the coordinates of the home button and simulate a long touch on those exact coordinates:

    device.touch(x, y, MonkeyDevice.DOWN)  
    MonkeyRunner.sleep(3)
    device.touch(x, y, MonkeyDevice.UP)
    

    Where (x, y) are the coordinates of the home button. You can get these by going to the developer options and select pointer location and observe the coordinates as you touch the home button.

    Also, there is a specific key event for app switching:

    device.press(' KEYCODE_APP_SWITCH', MonkeyDevice.DOWN_AND_UP)
    

    This should open the recent apps panel.