脚本录制

网上先是搜索了一下,说是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录制和回放功能的更多相关文章

  1. Android自动化测试之MonkeyRunner录制和回放脚本

    Android自动化测试之MonkeyRunner录制和回放脚本(十一) 分类: 自动化测试 Android自动化 2013-02-22 10:57 7346人阅读 评论(2) 收藏 举报 andro ...

  2. Monkeyrunner 录制脚本&回放

    本文主要解释如何使用monkeyrunner来实现脚本的录制和回放 一:准备条件 在电脑端配置 Android SDK环境   java 环境 下载好 SDK后添加环境变量   E:\android- ...

  3. [转] Android自动化测试之MonkeyRunner录制和回放脚本(四)

    测试脚本录制: 方案一: 我们先看看以下monkeyrecoder.py脚本: #Usage: monkeyrunner recorder.py #recorder.py  http://mirror ...

  4. 【转】Android自动化测试之MonkeyRunner录制和回放脚本(四)

    测试脚本录制: 方案一: 我们先看看以下monkeyrecoder.py脚本: #Usage: monkeyrunner recorder.py #recorder.py  http://mirror ...

  5. Android自动化学习笔记之MonkeyRunner:MonkeyRunner的录制和回放

    ---------------------------------------------------------------------------------------------------- ...

  6. Unity-Animator深入系列---录制与回放

    回到 Animator深入系列总目录 Animator自带了简单的动画录制,回放功能.但可惜的是不支持持久化的数据输出.因而不能作为录像保存 不过这种可以作为竞速,格斗类游戏在结束时经常出现的游戏回放 ...

  7. 性能测试--Jmeter录制、回放

    Jmeter录制.回放 在jmeter2.1版本之前,jmeter应该是不支持录制和回放功能的,那时候如果需要录制jmeter的性能测试脚本的话,就需要使用第三方工具——badboy.现在jmeter ...

  8. monkeyrunner之录制与回放(七)

    monkeyrunner为我们提供了录制 回放的功能. 录制与回放使用原因:实际项目,需求变更频繁,且测试任务多,我们没有足够时间去写测试脚本,这是就可以进行录制脚本,然后通过回放,跑完需要的流程. ...

  9. IOS开发之小实例--创建一个简单的用于视频录制和回放的应用程序

    前言:还是看了一下国外的入门IOS文章:<Create a Simple App for Video Recording and Playback>,主要涉及视频录制和回放的功能的基本实现 ...

随机推荐

  1. Linux服务知识点总结

    一.firewalld防火墙 1.firewalld简述 firewalld:防火墙,其实就是一个隔离工具:工作于主机或者网络的边缘.对于进出本主机或者网络的报文根据事先定义好的网络规则做匹配检测,对 ...

  2. VMware 虚拟机安装Mac OS X 10.10

    有图有真相,哈哈 一.下载以上文件 1. vm百度软件下载即可,版本都能满足需要,随意好了 2. unlocker 207 3. Mac OS X 10.10镜像 二.基本步骤 1. 虚拟机的安装 下 ...

  3. 【并行计算-CUDA开发】有关CUDA当中global memory如何实现合并访问跟内存对齐相关的问题

    ps:这是英伟达二面面的一道相关CUDA的题目.<NVIDIA CUDA编程指南>第57页开始          在合并访问这里,不要跟shared memory的bank conflic ...

  4. history 命令

    history 命令用来显示执行过的命令,也可以根据显示的命令重新执行需要的命令. 用法: n 显示n个最近的记录 -a 添加记录到history文件中 -c 将目前shell中的所有history命 ...

  5. Oracle-DQL 3- 单行函数

    单行函数: --使用函数对表中的数据进行运算和处理,针对每行数据返回一个结果,叫做单行函数--包括数字函数,字符函数,日期函数,转换函数,其他函数 1.数字函数 --round(m,n) 将数字m精确 ...

  6. JavaScript--QuckStudy

    Day1: 初识JS: https://www.liaoxuefeng.com/wiki/1022910821149312 >打印: alert('我要学JavaScript!'); >J ...

  7. 201803-3 URL映射

    问题描述 URL 映射是诸如 Django.Ruby on Rails 等网页框架 (web frameworks) 的一个重要组件.对于从浏览器发来的 HTTP 请求,URL 映射模块会解析请求中的 ...

  8. sysbench测试

    什么是基准测试 数据库的基准测试是对数据库的性能指标进行定量的.可复现的.可对比的测试. 基准测试与压力测试 基准测试可以理解为针对系统的一种压力测试.但基准测试不关心业务逻辑,更加简单.直接.易于测 ...

  9. django 中间键重定向

    1,定义和注册中间件 在注册的中间件中使用: from django.http import HttpResponseRedirect '''下面的书写方法会陷入死循环,所以必须加判断条件只调用一次' ...

  10. 关于学习电信nb-iot的小结

    关于这几天对nb-iot的学习的总结和遇到的坑 初步学习nb-iot,了解到了nb-iot对于传感器数据传输功能的强大: 废话不多说,对于nb-iot我们选择的有人的模块,选择B5频段也就是电信的nb ...