测试脚本录制:

方案一:

我们先看看以下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. Delphi-仿vb里的IIF函数

    //Delphi 函数-IIF // 实例-ChkValue := IIF(TCheckBox(tsPzJz.Controls[i]).Checked, '); function IIF(lExp: ...

  2. 可变参数列表---以dbg()为例

    在UART驱动的drivers/serial/samsung.h中遇到如下定义: #ifdef CONFIG_SERIAL_SAMSUNG_DEBUG extern void printascii(c ...

  3. Hello,iOS

    xcode 6.1 File-New-Project.. iOs-Application-Simple View Application Main.storyboard ==> 拖一个TextV ...

  4. Android中9patch图片格式(xx.9.png)介绍与制作详解

    一:9patch图片介绍: android的.9.png是android系统中一种特殊的图片格式,专门用来用来处理图片大小变化后(如拉伸)的失真,不正常,如我们看到的qq聊天中的文字气泡,不管你输入的 ...

  5. MyEclipse 8.5配置Tomcat7.0

    MyEclipse 8.5配置默认没有Tomcat7.0, 如果想使用怎么办.? window>>Preferences>>MyEclipse Enterprise Workb ...

  6. 前端跨域之html5 XMLHttpRequest Level2

    前端代码 var xhr=new XMLHttpRequest(); xhr.open('POST','http://127.0.0.1:8081/ceshi',true); xhr.onreadys ...

  7. poj 2060 Taxi Cab Scheme (最小路径覆盖)

    http://poj.org/problem?id=2060 Taxi Cab Scheme Time Limit: 1000MS   Memory Limit: 30000K Total Submi ...

  8. 1061: [Noi2008]志愿者招募 - BZOJ

    Description 申奥成功后,布布经过不懈努力,终于成为奥组委下属公司人力资源部门的主管.布布刚上任就遇到了一个难题:为即将启动的奥运新项目招募一批短期志愿者.经过估算,这个项目需要N 天才能完 ...

  9. 1058: [ZJOI2007]报表统计 - BZOJ

    Description 小Q的妈妈是一个出纳,经常需要做一些统计报表的工作.今天是妈妈的生日,小Q希望可以帮妈妈分担一些工作,作为她的生日礼物之一.经过仔细观察,小Q发现统计一张报表实际上是维护一个非 ...

  10. mysql 增加删除用户

    mysql 增加用户 (注意:因为MYSQL环境中的命令,所以后面都带一个分号作为命令结束符) 格式:grant select on 数据库.* to 用户名@登录主机 identified by ' ...