monkeyrunnermonkeyrunner脚本录制和回放
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了monkeyrunnermonkeyrunner脚本录制和回放相关的知识,希望对你有一定的参考价值。
脚本录制
1.连接你已经打开调试模式的android设备或模拟器,输入adb devices
2.运行录制脚本。在cmd窗口输入 monkeyrunner recorder.py
#recorder.py
__author__ = ‘paul‘ from com.android.monkeyrunner import MonkeyRunner as mr from com.android.monkeyrunner.recorder import MonkeyRecorder as recorder device = mr.waitForConnection() recorder.start(device)
3. 启动模拟机,就可以录制脚本了,右侧的代码是你的操作步骤。
4.录制完成后,点击Export Actions,然后选择一个文件夹进行保存。
附录:
命令行下执行monkeyrunner record.py
提示错误如下:
Can‘t open specified script file
Usage: monkeyrunner [options] SCRIPT_FILE
-s MonkeyServer IP Address.
-p MonkeyServer TCP Port.
-v MonkeyServer Logging level (ALL, FINEST, FINER, FINE, CONFIG, INFO, WARNING, SEVERE, OFF)
解决办法:
monkeyrunner record.py的全路径
脚本回放
1.首先我们先查看下录制的脚本
2.开始回放脚本。需要注意的时,回放时的app初始页面要和录制时一致。
在cmd窗口输入monkeyrunner playback.py jiaoben
import sys from com.android.monkeyrunner import MonkeyRunner CMD_MAP = { "TOUCH": lambda dev, arg: dev.touch(**arg), "DRAG": lambda dev, arg: dev.drag(**arg), "PRESS": lambda dev, arg: dev.press(**arg), "TYPE":lambda dev, arg:dev.type(**arg), "WAIT":lambda dev, arg:MonkeyRunner.sleep(**arg) } #Process a single file for the specified device. def process_file(fp,device): for line in fp: (cmd,rest) = line.split("|") try: #Parse the pydict rest = eval(rest) except: print "unable to parse options" continue if cmd not in CMD_MAP: print "unknown command: " + cmd continue CMD_MAP[cmd](device, rest) def main(): file = sys.argv[1] fp = open(file, "r") device = MonkeyRunner.waitForConnection() process_file(fp,device) fp.close(); if __name__ == "__main__": main()
3.观看自己手机就能自动运行了
附录:
命令行下执行monkeyrunner playback.py
提示错误如下:
解决办法:
monkeyrunner playback.py 的全路径
以上是关于monkeyrunnermonkeyrunner脚本录制和回放的主要内容,如果未能解决你的问题,请参考以下文章