monkeyrunner录制和回放功能
脚本录制
网上先是搜索了一下,说是SDK--tools目录下有monkey_recorder.py和monkey_playback.py的脚本,但是我的没有找到所以可以自己编辑个脚本保存即可~
先编辑以下代码为monkey_recorder.py,保存在tools中
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()
然后执行,monkeyrunner monkey_recorder.py,会出现一个录制弹窗

Wait 是设置等待时间
press a Button 是发送MENU HOME SEARCH按钮的Press Down Up响应事件
type something 是输入字符
Fling 是模拟东西南北的拖动操作
Export Actions 是导出脚本
Refresh Display 是刷新功能
然后就可以进行录制app操作了~

最后导出export Action,cmd中回放此导出文件即可
monkeyrunner monkey_playback.py 导出脚本路径
monkeyrunner录制和回放功能的更多相关文章
- Android自动化测试之MonkeyRunner录制和回放脚本
Android自动化测试之MonkeyRunner录制和回放脚本(十一) 分类: 自动化测试 Android自动化 2013-02-22 10:57 7346人阅读 评论(2) 收藏 举报 andro ...
- Monkeyrunner 录制脚本&回放
本文主要解释如何使用monkeyrunner来实现脚本的录制和回放 一:准备条件 在电脑端配置 Android SDK环境 java 环境 下载好 SDK后添加环境变量 E:\android- ...
- [转] Android自动化测试之MonkeyRunner录制和回放脚本(四)
测试脚本录制: 方案一: 我们先看看以下monkeyrecoder.py脚本: #Usage: monkeyrunner recorder.py #recorder.py http://mirror ...
- 【转】Android自动化测试之MonkeyRunner录制和回放脚本(四)
测试脚本录制: 方案一: 我们先看看以下monkeyrecoder.py脚本: #Usage: monkeyrunner recorder.py #recorder.py http://mirror ...
- Android自动化学习笔记之MonkeyRunner:MonkeyRunner的录制和回放
---------------------------------------------------------------------------------------------------- ...
- Unity-Animator深入系列---录制与回放
回到 Animator深入系列总目录 Animator自带了简单的动画录制,回放功能.但可惜的是不支持持久化的数据输出.因而不能作为录像保存 不过这种可以作为竞速,格斗类游戏在结束时经常出现的游戏回放 ...
- 性能测试--Jmeter录制、回放
Jmeter录制.回放 在jmeter2.1版本之前,jmeter应该是不支持录制和回放功能的,那时候如果需要录制jmeter的性能测试脚本的话,就需要使用第三方工具——badboy.现在jmeter ...
- monkeyrunner之录制与回放(七)
monkeyrunner为我们提供了录制 回放的功能. 录制与回放使用原因:实际项目,需求变更频繁,且测试任务多,我们没有足够时间去写测试脚本,这是就可以进行录制脚本,然后通过回放,跑完需要的流程. ...
- IOS开发之小实例--创建一个简单的用于视频录制和回放的应用程序
前言:还是看了一下国外的入门IOS文章:<Create a Simple App for Video Recording and Playback>,主要涉及视频录制和回放的功能的基本实现 ...
随机推荐
- hdoj1011(树上分组背包)
题目链接:https://vjudge.net/problem/HDU-1011 题意:给定一颗树,每个结点有两个属性,即花费V和价值w,并且选择子结点时必须选择父结点,求总花费不超过m的最大价值. ...
- 如何给django admin.py配置超级管理员?注册表格?
admin.py是django给我们提供的功能非常强大的后台,况且支持拓展,,如果你要是觉得admin的后台不够牛逼你可以自己写一个!如何自己写一个后台,后面我有时间了会给大家更新!一起学习!一起进步 ...
- 合并两个排序链表——牛客offer
题目描述: 输入两个单调递增的链表,输出两个链表合成后的链表,当然我们需要合成后的链表满足单调不减规则. 解题思路: 1.一般看到合并这类的题目就会很自然的想到创建一个新的链表,然后将两个链表根据一定 ...
- Spring 基于 AspectJ 的 AOP 开发
Spring 基于 AspectJ 的 AOP 开发 在 Spring 的 aop 代理方式中, AspectJ 才是主流. 1. AspectJ 简介 AspectJ 是一个基于 java 语言的 ...
- Lua访问网页
示例 例子,实现https方式,登录网站,访问某个网页,修改其中参数的功能.其中xx应用时候需要修改. require("curl") local ipList = { " ...
- C#取绝对值函数
System.Math.Abs(float value); System.Math.Abs(decimal value); System.Math.Abs(int value); System.Mat ...
- # 风险定性(Qualitative)分析
1. 从一个给教师打分的设计表说起 我们参加一个培训课程,一般在培训结束之后,培训机构一般都会分发一份培训师培训效果反馈表,用于评价其讲师的培训能力的强弱. 如果是一家没有什么经验的培训机构设计的反馈 ...
- 向PHP发送HTTP-Get请求
1.get.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...
- php-fpm三种运行模式
php-fpm配置 配置文件:php-fpm.conf 开启慢日志功能的: slowlog = /usr/local/var/log/php-fpm.log.slowrequest_slowlog_t ...
- MYSQL 修改语句(数据)
修改数据(UPDATE) 如果你失忆了,希望你能想起曾经为了追求梦想的你. 我们玩QQ.微信.淘宝等等,都会有一个操作:修改信息 淘宝常用的嘛,新增了收货地址,也可以修改它,微信/ ...