创建python文件fling.py,代码如下:
#!/usr/bin/env monkeyrunner
import time
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
device = MonkeyRunner.waitForConnection(5)
loop = 0
loop_back = 0
# fling up
def scrollUpFling():
device.touch(100, 500, MonkeyDevice.DOWN)
device.touch(100, 100, MonkeyDevice.MOVE)
device.touch(100, 100, MonkeyDevice.UP)
print "fling up"
# fling down
def scrollDownFling():
device.touch(100, 400, MonkeyDevice.DOWN)
device.touch(100, 500, MonkeyDevice.MOVE)
device.touch(100, 500, MonkeyDevice.UP)
print "fling down"
# click
def clickItem():
device.touch(600,600,'DOWN_AND_UP')
print "click item"
# back
def back():
device.touch(60,160,'DOWN_AND_UP')
print "back item"
def fling():
global loop
global loop_back
while True:
scrollUpFling()
time.sleep(5)
scrollDownFling()
time.sleep(5)
scrollUpFling()
time.sleep(5)
loop = loop + 1;
loop_back = loop_back + 1;
if (loop > 3):
loop = 0;
clickItem()
if (loop_back > 30):
loop_back = 0
back()
fling()
使用cmd工具,执行monkeyrunner C:\Users\andre.ou\Desktop\fling.py