monkeyrunner学习笔记四(录制和回放)
来源:互联网 发布:路由器上面的访客网络 编辑:程序博客网 时间:2024/06/06 16:35
首先电脑已经搭配好SDK的环境
录制
1. 把以下的脚本复制粘贴后保存为recorder.py的文件,并且把recorder.py文件放在SDK---Tools目录下。
#!/usr/bin/envmonkeyrunner
#Copyright 2010, The Android Open Source Project
#
#Licensed under the Apache License, Version 2.0 (the "License");
# you maynot use this file except in compliance with the License.
# You mayobtain a copy of the License at
#
#http://www.apache.org/licenses/LICENSE-2.0
#
# Unlessrequired by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUTWARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See theLicense for the specific language governing permissions and
#limitations under the License.
fromcom.android.monkeyrunner import MonkeyRunner as mr
fromcom.android.monkeyrunner.recorder import MonkeyRecorder as recorder
device =mr.waitForConnection()
recorder.start(device)
2.保存后,在cmd窗口tools目录下,输入recorder.py
3.点击预览界面的控件,在右边会出现点击的坐标。录制过程中,每个控件之间应该点击Wait,等待下时间。
4.录制完成后,点击ExportActions按钮,保存文件,把文件保存到tools目录下,并且保存为XX.py文件。
回放
把以下代表复制粘贴并且保存文件为recorder_playback.py
#!/usr/bin/env monkeyrunner
# Copyright 2010, The Android Open SourceProject
#
# Licensed under the Apache License,Version 2.0 (the "License");
# you may not use this file except incompliance 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 oragreed to in writing, software
# distributed under the License isdistributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANYKIND, either express or implied.
# See the License for the specific languagegoverning permissions and
# limitations under the License.
import sys
from com.android.monkeyrunner importMonkeyRunner
# The format of the file we are parsing isvery carfeully constructed.
# Each line corresponds to a singlecommand. 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 intoexistence) that specifies the
# arguments for the command. In most cases, this directly maps to the
# keyword argument dictionary that could bepassed to the underlying
# command.
# Lookup table to map command strings tofunctions 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 specifieddevice.
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()
2.在cmd窗口tools目录下输入monkeyrunnerrecorder_playback.py xx.py
- monkeyrunner学习笔记四(录制和回放)
- monkeyrunner的录制和回放学习总结
- Android自动化测试之MonkeyRunner录制和回放脚本(四)
- Android自动化测试之MonkeyRunner录制和回放脚本(四)
- android自动化测试之--MonkeyRunner录制和回放脚本(四)
- Android Monkeyrunner的录制和回放功能
- monkeyrunner(3)录制与回放脚本
- monkeyrunner 录制回放
- Monkeyrunner 录制脚本&回放
- monkeyrunner录制、回放
- MonkeyRunner 录制与回放
- monkeyrunner的录制与回放
- Android自动化测试之MonkeyRunner录制和回放脚本(十一)
- Android自动化测试之MonkeyRunner录制和回放脚本
- Selenium学习笔记之002:IDE录制和回放
- MonkeyRunner之MonkeyRecorder录制回放脚本
- monkeyrunner自动化测试工具--录制回放
- MonkeyRunner脚本的录制与回放分享
- jQuery 请指出'$'和'$.fn'的区别?或者说出'$.fn'的用途。
- 泛型,Quick Sort 的C/C++两种实现方式
- POJ 2993:Emag eht htiw Em Pleh:模拟题
- opencv实践程序6——简单(otsu)的背景差分法
- 加措活佛:幸福在心里
- monkeyrunner学习笔记四(录制和回放)
- IOS UILabel 如何实现随机摆放以及刷新
- 跳转到系统相簿界面,通讯录界面等后标题显示的英文,关键是手机已经设置显示中文了。
- Ubuntu命令入门
- The first time:数据结构作业——自定义链表及其操作
- Ant生成Java帮助文档doc
- 初级程序员的福音:C/C++面试题,都会包你过关
- android apk使用系统签名之windows批处理
- 用ultraedit实现编码转换