Monkeyrunner 录制脚本&回放
本文主要解释如何使用monkeyrunner来实现脚本的录制和回放
一:准备条件
在电脑端配置 Android SDK环境 java 环境
下载好 SDK后添加环境变量 E:\android-sdk-windows\tools 添加到path上
查看adb环境搭配成功与否
输入cmd-回车-输入adb shell
显示如下

OK 这样就adb配置环境好了
java环境同上原理 就不一一说了
二: 用到的录制、回放脚本
录制脚本: monkey_recorder.py
#!/usr/bin/env monkeyrunner
# Copyright 2010, The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License. from com.android.monkeyrunner import MonkeyRunner as mr
from com.android.monkeyrunner.recorder import MonkeyRecorder as recorder device = mr.waitForConnection()
recorder.start(device)
回放脚本: monkey_playback.py
#!/usr/bin/env monkeyrunner
# Copyright 2010, The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License. import sys
from 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()
三: 使用方法,在CMD下进入android的sdk下的tools目录下,进行下面的操作
录制: 1、在cmd下输入monkeyrunner monkey_recorder.py,将打开下面的窗口
该窗口的功能:
1、可以自动显示手机当前的界面
2、自动刷新手机的最新状态
3、点击手机界面即可对手机进行操作,同时会反应到真机,而且会在右侧插入操作脚本
4:、wait: 用来插入下一次操作的时间间隔,点击后即可设置时间,单位是秒
Press a Button:用来确定需要点击的按钮,包括menu、home、search,以及对按钮的press、down、up属性
Type Something:用来输入内容到输入框
Fling:用来进行拖动操作,可以向上、下、左、右,以及操作的范围
Export Actions:用来导出脚本
Refresh Display:用来刷新手机界面,估计只有在断开手机后,重新连接时才会用到

最后一个为录制的文件,这里需要使用绝对路径
PS: 录制后的脚本可以进行二次更改,而且每一步操作需要有时间间隔,以保证测试的正确性
欢迎关注老王公众号

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录制和回放脚本(四)
测试脚本录制: 方案一: 我们先看看以下monkeyrecoder.py脚本: #Usage: monkeyrunner recorder.py #recorder.py http://mirror ...
- monkeyrunner录制和回放功能
脚本录制 网上先是搜索了一下,说是SDK--tools目录下有monkey_recorder.py和monkey_playback.py的脚本,但是我的没有找到所以可以自己编辑个脚本保存即可~ 先编辑 ...
- 【monkeyrunner】monkeyrunner脚本录制和回放
脚本录制 1.连接你已经打开调试模式的ANDROID设备或模拟器,输入adb devices 2.运行录制脚本.在cmd窗口输入 monkeyrunner recorder.py #recorder. ...
- Monkeyrunner脚本的录制与回放
继上一篇monkeyrunner环境搭建:http://www.cnblogs.com/zh-ya-jing/p/4351245.html 之后,我们可以进一步学习monkeyrunner了. 我也是 ...
- MonkeyRunner Mac环境 录制脚本和回放 批量回放
1.MonkeyRunner是AndroidSDK自带的一个东西,在SDK目录中的tools\bin文件夹中 2.配置环境变量 编辑环境变量:打开终端输入:open ~/.bash_profile 将 ...
- monkeyrunner之录制与回放(七)
monkeyrunner为我们提供了录制 回放的功能. 录制与回放使用原因:实际项目,需求变更频繁,且测试任务多,我们没有足够时间去写测试脚本,这是就可以进行录制脚本,然后通过回放,跑完需要的流程. ...
- Android自动化学习笔记之MonkeyRunner:MonkeyRunner的录制和回放
---------------------------------------------------------------------------------------------------- ...
随机推荐
- 消除ImageButton背景图片
下图被选为作为ImageButton的Src,可它自带了个灰色的背景图,而我只想用这个圆圈作为imageButton的src,这怎么办呢? 遇到此情况可以设置imagebutton的backgroun ...
- LEMP (LNMP) Stack-5.4.16 (OpenLogic CentOS 7.2)
LEMP (LNMP) Stack-5.4.16 (OpenLogic CentOS 7.2) 平台: CentOS 类型: 虚拟机镜像 软件包: mariadb-5.5.47 nginx-1.6.3 ...
- 又一次摔MFC坑里了
因为公司的个项目最近开始写MFC了,又遇到一个坑爹的问题,使用的View视图模式在VS2010中创建的工程,默认就带入了许多的Style,例如Office 2007的许多漂亮样式确实很方便,但是同样也 ...
- String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getSer
这其实就是 获得应用的根url,比如说你的应用的根路径是 http://localhost:8080,那么你列出的代码就是为basePath赋值为 http://localhost:8080.具体点: ...
- 3204: 数组做函数参数--排序函数2--C语言
3204: 数组做函数参数--排序函数2--C语言 时间限制: 1 Sec 内存限制: 128 MB提交: 211 解决: 143[提交][状态][讨论版][命题人:smallgyy] 题目描述 ...
- json文件的读取
在客户端读取后台的json文件,使用jquery的$.getJSON,读取后台文件内容. jQuery中的$.getJSON( )方法函数主要用来从服务器加载json编码的数据,它使用的是GET HT ...
- 在mininet上基于ovs,ovx,pox搭建三点虚拟网络
本次试验基于mininet平台,在平台中利用ovs新建1个交换机,以pox为控制器,ovx作为中间层实现虚拟化. 基础请参照http://ovx.onlab.us/getting-started/tu ...
- BZOJ2287: 【POJ Challenge】消失之物(背包dp)
题意 ftiasch 有 N 个物品, 体积分别是 W1, W2, ..., WN. 由于她的疏忽, 第 i 个物品丢失了. “要使用剩下的 N - 1 物品装满容积为 x 的背包,有几种方法呢?” ...
- mysql 存储过程 例子
DROP PROCEDURE IF EXISTS variable_demo; delimiter // CREATE PROCEDURE variable_demo() BEGIN select ' ...
- WebUploader压缩图片上传
WebUploader,由Baidu FEX 团队开发,以H5为主,FLASH为辅,兼容 IE6+,iOS 6+, android 4+,采用大文件分片并发上传,极大的提高了文件上传效率,看了官方文档 ...