【转】Android自动化测试之MonkeyRunner录制和回放脚本(四)
测试脚本录制:
方案一:
我们先看看以下monkeyrecoder.py脚本:
- #Usage: monkeyrunner recorder.py
- #recorder.py http://mirror.yongbok.net/linux/ ... ey_recorder.py;
- com.android.monkeyrunner import MonkeyRunner as mr
- com.android.monkeyrunner.recorder import MonkeyRecorder as recorder
- device = mr.waitForConnection()
- recorder.start(device)
- #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
- #Usage: monkeyrunner playback.py "myscript"
- #playback.py http://mirror.yongbok.net/linux/ ... ey_playback.py;
- import sys
- com.android.monkeyrunner import MonkeyRunner
- # The format of the file we are parsing is very carfeully constructed.
- # Each line corresponds to a single command. The line is split into 2
- # parts with a | character. Text to the left of the pipe denotes
- # which command to run. The text to the right of the pipe is a python
- # dictionary (it can be evaled into existence) that specifies the
- # arguments for the command. In most cases, this directly maps to the
- # keyword argument dictionary that could be passed to the underlying
- # command.
- # Lookup table to map command strings to functions that implement that
- # command.
- 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()
=================================================
Usage:monkeyrunner playback.py "myscript"
【转】Android自动化测试之MonkeyRunner录制和回放脚本(四)的更多相关文章
- Android自动化测试之MonkeyRunner录制和回放脚本
Android自动化测试之MonkeyRunner录制和回放脚本(十一) 分类: 自动化测试 Android自动化 2013-02-22 10:57 7346人阅读 评论(2) 收藏 举报 andro ...
- [转] Android自动化测试之MonkeyRunner录制和回放脚本(四)
测试脚本录制: 方案一: 我们先看看以下monkeyrecoder.py脚本: #Usage: monkeyrunner recorder.py #recorder.py http://mirror ...
- Android自动化测试之Monkeyrunner学习笔记(一)
Android自动化测试之Monkeyrunner学习笔记(一) 因项目需要,开始研究Android自动化测试方法,对其中的一些工具.方法和框架做了一些简单的整理,其中包括Monkey.Monkeyr ...
- Android自动化测试之MonkeyRunner使用
MonkeyRunner工具是使用Jython(使用Java编程语言实现的Python)写出来的,它提供了多个API,通过monkeyrunner API 可以写一个Python的程序来模拟操作控制A ...
- Android自动化测试之MonkeyRunner
1.Monkeyrunner简介 Monkeyrunner是Android系统自带的四大自动化测试工具之一,其他三个是Monkey.CTS.Benchmark:Monkeyrunner需要通过Andr ...
- [转] android自动化测试之MonkeyRunner使用实例(三)
一.使用CMD命令打开模拟器 运行monkeyrunner之前必须先运行相应的模拟器或连上设备,不然monkeyrunner无法连接设备. 1.1 用Elipse打开Android模拟器或在CMD中 ...
- 【转】android自动化测试之MonkeyRunner使用实例(三)
一.使用CMD命令打开模拟器 运行monkeyrunner之前必须先运行相应的模拟器或连上设备,不然monkeyrunner无法连接设备. 1.1 用Elipse打开Android模拟器或在CMD中 ...
- Android自动化测试之monkeyrunner工具
一.什么是monkeyrunner monkeyrunner工具提供了一个API,使用此API写出的程序可以在Android代码之外控制Android设备和模拟器.通过monkeyrunner,您可以 ...
- Android自动化测试之Monkeyrunner使用方法及实例
目前Android SDK里自带的现成的测试工具有monkey 和 monkeyrunner两个.大家别看这俩兄弟名字相像,但其实是完完全全不同的两个工具,应用在不同的测试领域.总的来说,monkey ...
随机推荐
- win10+vs2013+Qt5.4 安装方法
环境:win10 cn_visual_studio_ultimate_2013_x86_dvd_3009109 qt-opensource-windows-x86-msvc2013_64_opengl ...
- rtems总结
rtems 历史背景及现状 常用的api 和参数介绍 rtems_interrupt_enable rtems_interrupt_is_in_progress rtems_cache_flush_r ...
- HW6.6
public class Solution { public static void main(String[] args) { int[] prime = new int[50]; prime[0] ...
- ffmpeg 的tutorial
可能是新的: https://github.com/chelyaev/ffmpeg-tutorial https://github.com/chelyaev/ffmpeg-tutorial.git 老 ...
- usb device selection
- ubuntu 运行android sdk 下的工具adb报bash: ./adb: No such file or directory
运行adb出现这种错误: bash: ./adb: No such file or directory 但adb确实存在. 可能1:你用的是64位的Linux,没装32位运行时库,安装 $ sud ...
- hdu4612-Warm up(边的双连通分量)
题意:有n个点,m条边,有重边.现在可以任意在图上添加一条边,求桥的最少数目. 题解:思路就是求出双连通分量之后缩点成为一棵树,然后求出树的直径,连接树的直径就能减少最多的桥. 难点在于:有!重!边! ...
- TCP/IP 相关总结
1. 三次握手协议 在TCP/IP协议中,TCP协议提供可靠的连接服务,采用三次握手建立一个连接. 第一次握手:建立连接时,客户端发送syn包(syn=j)到服务器,并进入SYN_SEND状态,等 ...
- soliworks三维机柜布局(三)绘制电气线路图
三维机柜布局中的自动布线是根据线路图中的电气连接属性布的.
- FreeModbus 精简版本(Only RTU) for M128 (Modbus Slave)
1.硬件连接: M128 PD3 INT3/TXD1 ---> PC 232COM Pin 2 PD2 INT2/RXD1 ---> PC 232COM Pin 3 GND ...