第8章5节《MonkeyRunner源码剖析》MonkeyRunner启动运行过程-运行测试脚本
来源:互联网 发布:知乎 汉语 不及物动词 编辑:程序博客网 时间:2024/05/22 15:57
MonkeyRunner在准备好AndroidDebugBridge和DeviceMonitor等服务之后,就基本上是解决了和目标设备通信的问题了,那往下需要做的就是把测试脚本运行起来了。
178 public static void main(String[] args) {179 MonkeyRunnerOptions options = MonkeyRunnerOptions.processOptions(args);180 181 if (options == null) {182 return;183 }184 185 186 replaceAllLogFormatters(MonkeyFormatter.DEFAULT_INSTANCE, options.getLogLevel());187 188 MonkeyRunnerStarter runner = new MonkeyRunnerStarter(options);189 int error = runner.run();190 191 192 System.exit(error);193 }194 }代码8-5-1 MonkeyRunnerStarter - Main
从以上代码和本章上面几节分析可知,MonkeyRunnerStarter在实例化MonkeyRunnerStarter的过程中启动了AndroidDebugBridge和DeviceMonitor,然后就会进入下一行189行去调用MonkeyRunnerStarter的run方法。
66 private int run() 67 { 68 String monkeyRunnerPath = System.getProperty("com.android.monkeyrunner.bindir") + File.separator + "monkeyrunner"; 69 70 71 Map<String, Predicate<PythonInterpreter>> plugins = handlePlugins(); 72 if (this.options.getScriptFile() == null) { 73 ScriptRunner.console(monkeyRunnerPath); 74 this.chimp.shutdown(); 75 return 0; 76 } 77 int error = ScriptRunner.run(monkeyRunnerPath, this.options.getScriptFile().getAbsolutePath(), this.options.getArguments(), plugins); 78 79 this.chimp.shutdown(); 80 return error; 81 }代码8-5-2 MonkeyRunnerStarter - run
- 68行:取得monkeyrunner脚本的绝对路径。“com.android.monkeyrunner.bindir"我们在前面分析过,它代表的就是你的sdk安装目录下的”/tools”,然后再加上文件分隔符”/”以及”monkeyrunner”这个脚本。所以最终的结果就类似于”/Users/apple/Develop/sdk/tools/monkeyrunner”
- 72-73行: 如果用户在命令行运行monkeyrunner时没有提供脚本文件路径这个参数,那么就调用ScriptRunner类的console来请求jython解析器打开一个交互窗口来让用户进行交互
- 74行: 用户停止交互关闭窗口时调用ChimpChat的shutDown方法来通知相应模块测试已经停止,以便它们做相应的处理。比如会给monkey服务发送“quit”命令,通知它测试已经停止
- 77行: 如果用户在命令行运行monkeyrunner时提供了脚本路径这个参数,那么调用的将会是ScriptRunner的run方法来将该脚本运行起来,其实里面最终调用的就是jython的解析器来运行脚本。
无论是打开交互console还是直接运行脚本,最终用到的都是jython解析器来做事情,比如我们进去ScriptRunner的run方法:
77 public static int run(String executablePath, String scriptfilename, Collection<String> args, Map<String, Predicate<PythonInterpreter>> plugins) 78 {... 94 PythonInterpreter python = new PythonInterpreter();...114 try115 {116 python.execfile(scriptfilename);117 }...}代码8-3-3 ScriptRunner - run
做的事情就是去实例化一个jython的解析器,PythonInterpreter所在的包是“org.python.util”。获得jython解析器后就直接调用解析器的execfile方法去执行目标测试脚本了。
注:更多文章请关注公众号:techgogogo或个人博客http://techgogogo.com。当然,也非常欢迎您直接微信(zhubaitian1)勾搭。本文由天地会珠海分舵原创。转载请自觉,是否投诉维权看心情。
1 0
- 第8章5节《MonkeyRunner源码剖析》MonkeyRunner启动运行过程-运行测试脚本
- 第8章1节《MonkeyRunner源码剖析》MonkeyRunner启动运行过程-运行环境初始化
- 第8章3节《MonkeyRunner源码剖析》MonkeyRunner启动运行过程-启动AndroidDebugBridge
- 第8章4节《MonkeyRunner源码剖析》MonkeyRunner启动运行过程-启动AndroidDebugBridge
- 第8章6节《MonkeyRunner源码剖析》MonkeyRunner启动运行过程-启动Monkey
- 第8章2节《MonkeyRunner源码剖析》MonkeyRunner启动运行过程-解析处理命令行参数
- 第8章7节《MonkeyRunner源码剖析》MonkeyRunner启动运行过程-小结
- 第5章3节《MonkeyRunner源码剖析》Monkey原理分析-启动运行: 启动脚本(原创)
- 第5章1节《MonkeyRunner源码剖析》Monkey原理分析-启动运行: 官方简介(原创)
- 第5章2节《MonkeyRunner源码剖析》Monkey原理分析-启动运行: 启动流程概览(原创)
- 第5章5节《MonkeyRunner源码剖析》Monkey原理分析-启动运行: 获取系统服务引用(原创)
- 第5章4节《MonkeyRunner源码剖析》Monkey原理分析-启动运行: 命令行参数解析(原创)
- 第5章6节《MonkeyRunner源码剖析》Monkey原理分析-启动运行: 初始化事件源(原创)
- 第5章7节《MonkeyRunner源码剖析》Monkey原理分析-启动运行: 循环获取并执行事件 - runMonkeyCycles(原创)
- 第3章1节《MonkeyRunner源码剖析》脚本编写示例: MonkeyRunner API使用示例(原创)
- 第14章5节《MonkeyRunner源码剖析》 HierarchyViewer实现原理-装备ViewServer-查询ViewServer运行状态
- 第3章2节《MonkeyRunner源码剖析》脚本编写示例: MonkeyDevice API使用示例(原创)
- 第3章3节《MonkeyRunner源码剖析》脚本编写示例: MonkeyImage API使用示例(原创)
- 【OpenCV学习笔记】3.1 RGB图像转换为HSI图像
- javaday16-集合框架
- 在ViewPager中添加ListView
- 5.1.4 I/O管理概述
- 4-9 UVA 1591 Data Mining 数据挖掘
- 第8章5节《MonkeyRunner源码剖析》MonkeyRunner启动运行过程-运行测试脚本
- JDK的动态代理实现原理理解
- 第8章6节《MonkeyRunner源码剖析》MonkeyRunner启动运行过程-启动Monkey
- 查询SQL强化练习
- 第8章7节《MonkeyRunner源码剖析》MonkeyRunner启动运行过程-小结
- 读取文件中的字符个数,包括空格等
- android操作自带的SQlite数据库
- 探索Popupwindow-对话框风格的窗口(
- 【Ruby】语言基础