#ref: http://www.cnblogs.com/youxilua/archive/2011/11/25/2262715.html
#mod: zxx
#导入我们需要用到的包和类并且起别名
import sys,time,os
from com.android.monkeyrunner import MonkeyRunner as mr
argc = len(sys.argv)
if argc < 2 :
print 'usage: %android_sdk%tools\monkeyrunner snapshot.py emulator-5554 [imagesavetofile]'
sys.exit(1)
#emulator-5554
devicename = sys.argv[1]
imgsavetofile = ''
if argc>=3 :
imgsavetofile = sys.argv[2]
print 'device name: ' + devicename
device = mr.waitForConnection(1.0,devicename)
#进行截图
snapshot = device.takeSnapshot()
#创建时间字符串
t = time.strftime("%Y-%m-%d-%X",time.localtime())
t = t.replace(":","-")
#保存截图
if imgsavetofile=='' :
imgsavetofile = 'snapshot/'+devicename+'-'+t+'.png'
if not os.path.exists('snapshot') :
os.mkdir('snapshot')
print 'snapshot image file: ' + imgsavetofile
snapshot.writeToFile(imgsavetofile,'png')
利用monkeyrunner对android模拟器截图的python脚本
最新推荐文章于 2024-04-10 21:10:51 发布
本文介绍了一段使用Python脚本自动化执行Android设备截图操作,并将截图保存到指定目录的方法。通过调用Android MonkeyRunner库,实现设备连接、截图、时间戳命名和文件保存等功能。

602

被折叠的 条评论
为什么被折叠?



