Marshal Chen
Marshal Chen

Reputation: 2005

The method "device.press" or "device.touch" of MonkeyRunner doesn't take effect

I want to use monkeyrunner to test my MainActivity,and I have edit a python file like below:

    from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
    device = MonkeyRunner.waitForConnection(10)
    device.press('KEYCODE_DPAD_DOWN')
    device.press('KEYCODE_DPAD_CENTER')
    device.touch(10,100, 'DOWN_AND_UP')
    device.touch(200,200, 'DOWN_AND_UP')
    result = device.takeSnapshot()
    result.writeToFile('shot2.png','png')

And then I open up my app and use the command of "monkeyrunner monkeyrunnerprogram2.py",but the monkey runner can do nothing except takesnapshot().It doesnot do anything above.
So is there anyway to solve the problem?

Upvotes: 1

Views: 4584

Answers (1)

Gabriel Porumb
Gabriel Porumb

Reputation: 1691

You could try to replace 'DOWN_AND_UP' with MonkeyDevice.DOWN_AND_UP. And you could also add some MonkeyRunner.sleep(time_in_seconds) to pause the script between the interactions.

To test if the device object was properly created you could use device.wake() which lights up the device's display. If this works, the touch and press methods should work also.

Upvotes: 2

Related Questions