Android自动化测试之MonkeyRunner录制和回放脚本
Android自动化测试之MonkeyRunner录制和回放脚本(十一)
对于MonkeyRunner,有些人可能会想,既然是Android自动化测试,离不开测试脚本,那么,我们可不可以录制测试脚本呢,答案是可以的。
我们先看看以下monkeyrecoder.py脚本:
- #Usage: monkeyrunner recorder.py
- #recorder.py http://mirror.yongbok.net/linux/android/repository/platform/sdk/monkeyrunner/scripts/monkey_recorder.py
- com.android.monkeyrunner import MonkeyRunner as mr
- com.android.monkeyrunner.recorder import MonkeyRecorder as recorder
- device = mr.waitForConnection()
- recorder.start(device)
- #END recorder.py
首先,连接你已经打开调试模式的ANDROID设备或模拟器,然后运行上面的脚本,例如在cmd窗口中执行命令: monkeyrunner monkeyrecoder.py
执行下面的代码后,将运行录制脚本的程序:
#Press ExportAction to save recorded scrip to a file
#Example of result:
#PRESS|{""name"":""MENU"",""type"":""downAndUp"",}
#TOUCH|{""x"":180,""y"":175,""type"":""downAndUp"",}
#TYPE|{""message"":"""",}
=================================================
这种脚本需要另外一个monkeyrunner的脚本来解释执行。monkeyplayback.py
- #Usage: monkeyrunner playback.py "myscript"
- #playback.py http://mirror.yongbok.net/linux/android/repository/platform/sdk/monkeyrunner/scripts/monkey_playback.py
- import sys
- 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()
=================================================
Usage:monkeyrunner playback.py "myscript"
Android自动化测试之MonkeyRunner录制和回放脚本相关推荐
- Android自动化测试之MonkeyRunner MonkeyDevice MonkeyImage API使用详解 脚本编写 脚本录制回放
MonkeyRunner 系列文章 MonkeyRunner简介 MonkeyRunner 三大模块 MonkeyRunner API MonkeyDevice API MonkeyImage API ...
- Android自动化测试之MonkeyRunner
2019独角兽企业重金招聘Python工程师标准>>> MonkeyRunner是Google Android SDK下的一个工具,用于自动化测试Android程序. Monkeyr ...
- android 自动化测试之monkeyrunner学习(三),自动化测试之Monkeyrunner
一.功能 Android自动化测试工具 二.环境配置 1 android-sdk 2 jdk 3 配置python环境 monkeyrunner在Android SDK的tools文件夹下 三.打开方 ...
- Android自动化测试之monkeyrunner基本要素(七)
2019独角兽企业重金招聘Python工程师标准>>> 1. #导入模块; from com.android.monkeyrunner import MonkeyRunne ...
- Android自动化测试之Monkey命令使用及monkey脚本编写
系列文章 Android自动化测试环境部署及adb sdkmanager avdmanager Monitor DDMS工具使用及命令详解 Android自动化测试之Monkey使用及monkey脚本 ...
- [转] android自动化之MonkeyRunner测试环境配置(一)
Android自动化测试之MonkeyRunner 一.Android自动化测试之环境搭建 1.1 Android-sdk介绍 ¢ SDK(Software development kit)软件开发 ...
- java appium_Android应用开发之AS+Appium+Java+Win自动化测试之Appium的Java测试脚本封装(Android测试)...
本文将带你了解Android应用开发AS+Appium+Java+Win自动化测试之Appium的Java测试脚本封装(Android测试),希望本文对大家学Android有所帮助. 一.为什么需要封 ...
- 功能自动化测试之QTP录制脚本(一)
说明:该篇博客是博主一字一码编写的,实属不易,请尊重原创,谢谢大家! 接着上一篇博客继续往下写 :https://blog.csdn.net/qq_41782425/article/details/1 ...
- 转 Android自动测试之monkeyrunner工具(二)
monkeyrunner工具 前言: 最近开始研究Android自动化测试方法,对其中的一些工具.方法和框架做了一些简单的整理,其中包括android测试框架.CTS.Monkey.Monkeyru ...
最新文章
- Day19-File操作-创建 删除,文件过滤
- linux每日命令,日常整理linux常用命令大全(收藏)
- 1.5 测试php解析
- 中判断字符串是否为空_java中的数字以及如何判断字符串是不是数字
- Eclipse CDT Hello World工程makefile分析
- stata F值缺失_stata面板数据回归操作之GMM
- Facebook 开启元宇宙模式!豪砸百亿是为什么?
- 部编版是什么版本_教材部编版和人教版的区别
- c语言中锁的作用,C语言中的多线程死锁
- redis优化查询的两种方式
- 80-600-020-原理-存储引擎-简介
- Okhttp 向服务器发送请求(请求头,表单,post json数据)...
- Linux各个文件夹介绍
- busybox源码剖析(1)---whoami.c
- mysql_TCL语言(事务)
- HTML5页面实现文件下载
- 关于学习Java中常用类的总结
- 【Python】视频转换成图片
- Vertica的这些事(四)—— 关于vertica常用函数介绍(持续更新ing)
- java 正则 惰性匹配_js正则表达式惰性匹配和贪婪匹配用法分析