标签:
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
无论是打开交互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 try 115 { 116 python.execfile(scriptfilename); 117 } ... }代码8-3-3 ScriptRunner - run
做的事情就是去实例化一个jython的解析器,PythonInterpreter所在的包是“org.python.util”。获得jython解析器后就直接调用解析器的execfile方法去执行目标测试脚本了。
注:更多文章请关注公众号:techgogogo或个人博客http://techgogogo.com。当然,也非常欢迎您直接微信(zhubaitian1)勾搭。本文由天地会珠海分舵原创。转载请自觉,是否投诉维权看心情。
第8章5节《MonkeyRunner源码剖析》MonkeyRunner启动运行过程-运行测试脚本
标签:
原文地址:http://blog.csdn.net/zhubaitian/article/details/50212811