增强型MonkeyRunner脚本计划
作者:网络转载 发布时间:[ 2013/12/26 15:03:29 ] 推荐标签:自动化
xxxx
核心运行脚本:
#导入我们需要用到的包和类并且起别名
import sys,time,datetime from com.android.monkeyrunner import
MonkeyRunner as mr from com.android.monkeyrunner import MonkeyDevice as
md from com.android.monkeyrunner import MonkeyImage as mi deviceslist = []
devices = [] snapshot = [] templist = [] f = open("devices.txt") while True:
line = f.readline() if line: templist.append(line.strip())
else: break;
f.close() templist.pop() for i in range(len(templist)):
deviceslist.append(templist[i].split(' ')) fc = open("componentName.txt")
complist = [] while True: comp = fc.readline() if comp:
complist.append(comp.strip())
else: break; fc.close() fp = open("apk.txt") apklist = []
while True: apk = fp.readline() if apk:
apklist.append(apk.strip()) else:
break; print 'apk list :'print apklist print 'start componentName list :'
print complist print 'devices list:'print deviceslist for i in range(1,len(deviceslist)):
print 'current devices:' print deviceslist[i]
devices.append(mr.waitForConnection(1.0,deviceslist[i][0]))
#安装apk文件
for j in range(len(apklist)):
devices[i-1].installPackage('apk/'+apklist[j])
#启动activity
for k in range(len(complist)):
print 'current start activity:'
print complist[k]
devices[i-1].startActivity(component=complist[k])
#设置延时秒数
mr.sleep(5.0)
#----------------
#这里可进行一定的UI操作
#----------------
#mr.sleep(3.0)
#进行截图
snapshot.append(devices[i-1].takeSnapshot())
print 'end snapshot'
#创建时间字符串
t = time.strftime("%Y-%m-%d-%X",time.localtime())
t = t.replace(":","-")
#保存截图
package = complist[k].replace('/.','.')
snapshot[0].writeToFile('takeSnapshot/'+deviceslist[i][0]+'-'+t+'-'+package+'.png','png');
snapshot.pop()
由于之前毫无编写python的经验,只能写成这样了,欢迎高手补充!!!!!!
使用:
把tools文件夹里面的全部文件,同样放在android sdk tools 文件夹下即可,运行takeSnap.bat可以获取到多个设备运行时的截图了,这个期间…你可以选择去泡一杯咖啡…耗时情况…看你要测试几个设备,还有如何测试了……
效果图:
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11