测试脚本录制:

方案一:

我们先看看以下monkeyrecoder.py脚本:

  1. #Usage: monkeyrunner recorder.py
  2. #recorder.py  http://mirror.yongbok.net/linux/ ... ey_recorder.py;
  3. com.android.monkeyrunner import MonkeyRunner as mr
  4. com.android.monkeyrunner.recorder import MonkeyRecorder as recorder
  5. device = mr.waitForConnection()
  6. recorder.start(device)
  7. #END recorder.py

首先,连接你已经打开调试模式的ANDROID设备或模拟器,然后运行上面的脚本,例如在cmd窗口中执行命令: monkeyrunner monkeyrecoder.py

执行下面的代码后,将运行录制脚本的程序:

#Press ExportAction to save recorded scrip to a file

#Example of result:
#PRESS|{""name"":""MENU"",""type"":""downAndUp"",}
#TOUCH|{""x"":180,""y"":175,""type"":""downAndUp"",}
#TYPE|{""message"":"""",}

=================================================

这种脚本需要另外一个monkeyrunner的脚本来解释执行。monkeyplayback.py

  1. #Usage: monkeyrunner playback.py "myscript"
  2. #playback.py   http://mirror.yongbok.net/linux/ ... ey_playback.py;
  3. import sys
  4. com.android.monkeyrunner import MonkeyRunner
  5. # The format of the file we are parsing is very carfeully constructed.
  6. # Each line corresponds to a single command.  The line is split into 2
  7. # parts with a | character.  Text to the left of the pipe denotes
  8. # which command to run.  The text to the right of the pipe is a python
  9. # dictionary (it can be evaled into existence) that specifies the
  10. # arguments for the command.  In most cases, this directly maps to the
  11. # keyword argument dictionary that could be passed to the underlying
  12. # command.
  13. # Lookup table to map command strings to functions that implement that
  14. # command.
  15. CMD_MAP = {
  16. ""TOUCH"": lambda dev, arg: dev.touch(**arg),
  17. ""DRAG"": lambda dev, arg: dev.drag(**arg),
  18. ""PRESS"": lambda dev, arg: dev.press(**arg),
  19. ""TYPE"": lambda dev, arg: dev.type(**arg),
  20. ""WAIT"": lambda dev, arg: MonkeyRunner.sleep(**arg)
  21. }
  22. # Process a single file for the specified device.
  23. def process_file(fp, device):
  24. for line in fp:
  25. (cmd, rest) = line.split(""|"")
  26. try:
  27. # Parse the pydict
  28. rest = eval(rest)
  29. except:
  30. print ""unable to parse options""
  31. continue
  32. if cmd not in CMD_MAP:
  33. print ""unknown command: "" + cmd
  34. continue
  35. CMD_MAP[cmd](device, rest)
  36. def main():
  37. file = sys.argv[1]
  38. fp = open(file, ""r"")
  39. device = MonkeyRunner.waitForConnection()
  40. process_file(fp, device)
  41. fp.close();
  42. if __name__ == ""__main__"":
  43. main()

=================================================

Usage:monkeyrunner playback.py "myscript"

[转] Android自动化测试之MonkeyRunner录制和回放脚本(四)的更多相关文章

  1. Android自动化测试之MonkeyRunner录制和回放脚本

    Android自动化测试之MonkeyRunner录制和回放脚本(十一) 分类: 自动化测试 Android自动化 2013-02-22 10:57 7346人阅读 评论(2) 收藏 举报 andro ...

  2. 【转】Android自动化测试之MonkeyRunner录制和回放脚本(四)

    测试脚本录制: 方案一: 我们先看看以下monkeyrecoder.py脚本: #Usage: monkeyrunner recorder.py #recorder.py  http://mirror ...

  3. Android自动化测试之Monkeyrunner学习笔记(一)

    Android自动化测试之Monkeyrunner学习笔记(一) 因项目需要,开始研究Android自动化测试方法,对其中的一些工具.方法和框架做了一些简单的整理,其中包括Monkey.Monkeyr ...

  4. Android自动化测试之MonkeyRunner使用

    MonkeyRunner工具是使用Jython(使用Java编程语言实现的Python)写出来的,它提供了多个API,通过monkeyrunner API 可以写一个Python的程序来模拟操作控制A ...

  5. Android自动化测试之MonkeyRunner

    1.Monkeyrunner简介 Monkeyrunner是Android系统自带的四大自动化测试工具之一,其他三个是Monkey.CTS.Benchmark:Monkeyrunner需要通过Andr ...

  6. [转] android自动化测试之MonkeyRunner使用实例(三)

    一.使用CMD命令打开模拟器 运行monkeyrunner之前必须先运行相应的模拟器或连上设备,不然monkeyrunner无法连接设备. 1.1  用Elipse打开Android模拟器或在CMD中 ...

  7. 【转】android自动化测试之MonkeyRunner使用实例(三)

    一.使用CMD命令打开模拟器 运行monkeyrunner之前必须先运行相应的模拟器或连上设备,不然monkeyrunner无法连接设备. 1.1  用Elipse打开Android模拟器或在CMD中 ...

  8. Android自动化测试之monkeyrunner工具

    一.什么是monkeyrunner monkeyrunner工具提供了一个API,使用此API写出的程序可以在Android代码之外控制Android设备和模拟器.通过monkeyrunner,您可以 ...

  9. Android自动化测试之Monkeyrunner使用方法及实例

    目前Android SDK里自带的现成的测试工具有monkey 和 monkeyrunner两个.大家别看这俩兄弟名字相像,但其实是完完全全不同的两个工具,应用在不同的测试领域.总的来说,monkey ...

随机推荐

  1. 弹性布局学习-详解 flex-direction【决定主轴的方向】(二)

    弹性布局学习-详解 flex-direction[决定主轴的方向](二)

  2. JS实现图片翻书效果示例代码

    js 图片翻书效果.  picture.html  <html xmlns="http://www.w3.org/1999/xhtml">  <head>  ...

  3. php 字母大小写转换的函数

    分享下,在php编程中,将字母大小写进行转换的常用函数. 1.将字符串转换成小写strtolower(): 该函数将传入的字符串参数所有的字符都转换成小写,并以小定形式放回这个字符串 2.将字符转成大 ...

  4. ecshop订单中配送方式报错

    警告内容:Warning: number_format() expects parameter 1 to be double, string given in D:\wamp\www\ecshop_o ...

  5. XE5 ANDROID平台 调用 webservice

    服务端需要midas.dll   XE5对android的平台支持很有吸引力,虽然目前用来直接开发应用到安卓市场卖赚钱可能性估计不大(安卓市场目前国内好像都是免费的天下),但是对于企业应用很是很有帮助 ...

  6. Linux vi 中搜索关键字

    当你用vi打开一个文件后,因为文件太长,如何才能找到你所要查找的关键字呢? 在vi里可没有菜单-〉查找 不过没关系,可以在命令模式下敲斜杆( / )这时在状态栏(也就是屏幕左下脚)就出现了 “/” 然 ...

  7. 高性能图文混排框架,构架顺滑的iOS应用-b

    About GallopGallop是一个功能强大.性能优秀的图文混排框架. Features主要用于解决以下需求: 滚动列表的性能优化.Gallop使用异步绘制.视图层级合并.观察mainRunlo ...

  8. php实现调用微信上传照片然后保存至服务器与数据库

    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>    <s ...

  9. Jquery Highcharts 选项配置 说明文档

    Highcharts提供大量的选项配置参数,您可以轻松定制符合用户要求的图表,下面为Highcharts常用的最核心的参数选项配置. Chart:图表区选项 Chart图表区选项用于设置图表区相关属性 ...

  10. php数组内容分页的例子(转)

    php数组内容分页代码 时间:2016-03-04 23:46:34来源:网络 导读:php数组内容分页代码,当前页如果大于总页数,当前页为最后一页,分页显示时,应该从多少条信息开始读取数据.   p ...