monkeyrunner简单使用及压力测试

来源:互联网 发布:大连软件职业学院 编辑:程序博客网 时间:2024/05/22 02:30

monkeyrunner简单使用:

首先进入你的sdk目录的tools里面有一个monkeyrunner工具

进入cmd你的tools目录输入monkeyrunner

接下来我们连接设备操作

这样我们就连接上一台设备,当然也可以我下面这样操作都是一样的

下面我们来看看怎样安装和卸载apk
device.installPackage('D:/text/test.apk')  //安装apk
device.startActivity(component='com.example.test/com.example.test.MainActivity') //启动这个apk(启动Activity)
time.sleep(1)
device.removePackage('com.example.test') //卸载apk

写文件
file_object = open('D:\\text.txt', 'w+')
file_object.write(time.asctime(time.localtime(time.time()))+'\n') //向text.txt写入时间


字符串发送到键盘
device.type('字符串')

唤醒设备屏幕(在设备屏幕上唤醒)
device.wake()

在指定位置发送触摸事件(x,y的单位为像素)
device.touch(x,y,TouchPressType-触摸事件类型)

发送到指定键的一个关键事件
device.press(参数1:键码,参数2:触摸事件类型)

下面是我的随机触摸500次的测试
from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImageimport randomimport timeimport osdevice=MonkeyRunner.waitForConnection()if not device:print "Please connect a device to start!"else:print "start test" #print time.asctime(time.localtime(time.time()))file_object = open('c:\\text.txt', 'w+')num = 0while (num < 500):x = random.randint(0,1280)y = random.randint(0,800)device.touch(x,y,"DOWN_AND_UP")print xprint yMonkeyRunner.sleep(0.5)num += 1file_object.write(str("value:")+str(x)+' '+str(y)+'\n')file_object.write(str("num=")+str(num)+'\n')file_object.writelines(time.asctime(time.localtime(time.time()))+'\n')file_object.write('logcat -v time *:W ' + '\n')file_object.close()

0 0
原创粉丝点击