入门monkeyrunner5-monkeyrunner demo2 批处理+jython脚本
批处理:
1 @echo off 2 rem 获取当前运行设备 3 adb devices>D:\devices.txt 4 rem 运行monkeyrunner 脚本 5 monkeyrunner D:\testapk\demo2.py
monkeyrunner的jython脚本,此脚本为多机测试android自带的计算机功能以后会慢慢完善:
#coding=utf-8 import time 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 = [] #获取devices列表 f = open("D:\devices.txt") while True: line = f.readline() #The line default is empty if line: templist.append(line.strip()) else: break; f.close() templist.pop() for i in range(len(templist)): deviceslist.append(templist[i].split('\t')) 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])) activity='com.android.calculator2/com.android.calculator2.Calculator' devices[i-1].startActivity(activity) mr.sleep(5.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('D:/testapk/takeSnapshot/'+deviceslist[i][0]+'.png','png'); snapshot.pop()