Question

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?

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top