MonkeyRunner_采用MonkeyRunner自动化测试
来源:互联网 发布:关于网络诈骗的例子 编辑:程序博客网 时间:2024/06/07 10:08
转载自:http://blog.csdn.net/vrix/article/details/6893944
既然是自动化测试,而且又需要写脚本,那是不是可以自动生成测试脚本呢?带着这个问题,我找到了下面的代码 monkeyrecoder.py
- #!/usr/bin/envmonkeyrunner
- # Copyright 2010, TheAndroid Open Source Project
- #
- # Licensed under theApache License, Version 2.0 (the "License");
- # you may not usethis file except in compliance with the License.
- # You may obtain acopy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required byapplicable law or agreed to in writing, software
- # distributed underthe License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIESOR CONDITIONS OF ANY KIND, either express or implied.
- # See the License forthe specific language governing permissions and
- # limitations underthe License.
- fromcom.android.monkeyrunner import MonkeyRunner as mr
- fromcom.android.monkeyrunner.recorder import MonkeyRecorder as recorder
- device =mr.waitForConnection()
- recorder.start(device)
首先,连接你已经打开调试模式的ANDROID设备,然后运行上面的脚本 monkeyrunner.bat monkeyrecoder.py
执行下面的代码后,将运行录制脚本的程序,截图如下:
这个软件就可以生成脚本。但是这个软件生成的脚本不是monkeyrunner可以直接运行的
TOUCH|{'x':243,'y':746,'type':'downAndUp',}
TOUCH|{'x':244,'y':763,'type':'downAndUp',}
DRAG|{'start':(384,320),'end':(76,320),'duration':1.0,'steps':10,}
这种脚本需要另外一个monkeyrunner的脚本来解释执行。monkeyplayback.py
- #!/usr/bin/envmonkeyrunner
- # Copyright 2010, TheAndroid Open Source Project
- #
- # Licensed under theApache License, Version 2.0 (the "License");
- # you may not usethis file except in compliance with the License.
- # You may obtain acopy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required byapplicable law or agreed to in writing, software
- # distributed underthe License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIESOR CONDITIONS OF ANY KIND, either express or implied.
- # See the License forthe specific language governing permissions and
- # limitations underthe License.
- import sys
- fromcom.android.monkeyrunner import MonkeyRunner
- # The format of thefile we are parsing is very carfeully constructed.
- # Each linecorresponds to a single command. Theline is split into 2
- # parts with a |character. Text to the left of the pipedenotes
- # which command torun. The text to the right of the pipeis a python
- # dictionary (it canbe evaled into existence) that specifies the
- # arguments for thecommand. In most cases, this directlymaps to the
- # keyword argumentdictionary that could be passed to the underlying
- # command.
- # Lookup table to mapcommand 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 singlefile 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_采用MonkeyRunner自动化测试
- 采用MonkeyRunner自动化测试(一)
- 采用MonkeyRunner自动化测试(二)
- android 自动化测试 monkeyrunner
- monkeyrunner自动化测试
- android monkeyRunner 自动化测试
- Android自动化测试Monkeyrunner
- android自动化测试MonkeyRunner
- android 自动化测试Monkeyrunner
- monkeyrunner自动化测试
- MonkeyRunner:Android自动化测试
- Monkeyrunner--自动化测试工具
- MonkeyRunner_用QTP运行monkeyrunner
- Android自动化测试之monkeyrunner
- Android自动化测试之monkeyrunner
- Android自动化测试之monkeyrunner
- Android自动化测试之MonkeyRunner
- Android自动化测试之Monkeyrunner
- MonkeyRunner_MonkeyRunner 录制和播放脚本
- (转)Ubuntu 10.04开机画面低分辨率问题解决方案
- VIM选择文本块
- 如何在CentOS上安装电影播放器
- z-index相关问题
- MonkeyRunner_采用MonkeyRunner自动化测试
- 女测试工程师的成长(1-4)
- Android UI【android 自定义dialog 多选项对话框】
- 网络质量指标及测试工具iperf
- PHP手册-后递增疑问
- 内存管理内幕
- 家常炒饼丝的做法
- 这些年、我收集的JQuery代码
- 用epoll实现异步的Echo服务器