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的录制和回放
---------------------------------------------------------------------------------------------------- ...
随机推荐
- Android中的Matrix(矩阵)
写在前面 看这篇笔记之前先看一下参考文章,这篇笔记没有系统的讲述矩阵和代码的东西,参考文章写的也有错误的地方,要辨证的看. 如何计算矩阵乘法 android matrix 最全方法详解与进阶(完整篇) ...
- POI 怎么设置Excel整列的CellStyle啊
POI 怎么设置Excel整列的CellStyle啊,而不是循环每个Cell.因为现在是生成Excel模板,不知道客户会输入多少行. 问题补充: 指尖言 写道 好像没有这个方法,CellStyle是C ...
- Spark运行命令示例
local单机模式:结果xshell可见:./bin/spark-submit --class org.apache.spark.examples.SparkPi --master local[1] ...
- 【51nod1743】雪之国度(最小生成树+倍增)
点此看题面 大致题意: 给你一张无向连通图,其中每条边的边权为这条边连接的两点的权值之差.每次询问两点之间是否存在两条不重复的路径,若存在则输出这两条路径上最大值的最小值. 大致思路 这题显然就是要让 ...
- Shell重启Tomcat脚本
#!/bin/bash echo -e "\n\n\n" #force kill flag,if equal [f] to force kill all flag="He ...
- JS中的async/await的执行顺序详解
虽然大家知道async/await,但是很多人对这个方法中内部怎么执行的还不是很了解,本文是我看了一遍技术博客理解 JavaScript 的 async/await(如果对async/await不熟悉 ...
- Luogu [P1958] 上学路线_NOI导刊2009普及(6)
上学路线_NOI导刊2009普及(6) 题目详见:上学路线_NOI导刊2009普及(6) 这是一道基础的DFS(深搜)题,堪称模板,是新手练习搜索与回溯的好题选. 大致思路:从(1,1)开始搜索,每次 ...
- Oracle小知识_长期总结
更新时间:2018年7月16日 11:22:28 一. 系统 1. 打开防火墙后 Oracle 无法链接 新建1521端口规则. 二.知识 A. 序列 1. nextval ------------- ...
- Angular2的笔记
1.如果启动项目的时候出现下列黄色的警告说明电脑安装的全局cli和项目中使用的cli版本不一致,不过不影响使用,按它的提示执行 ng set --global warnings.versionMism ...
- 【算法】Fibonacci(斐波那契数列)相关问题
一.列出Fibonacci数列的前N个数 using System; using System.Collections.Generic; using System.Linq; using System ...