Android自动化测试之MonkeyRunner录制和回放脚本(十一)

分类: 自动化测试 Android自动化 2013-02-22 10:57 7346人阅读 评论(2) 收藏 举报
androidAndroidANDROIDMonkeyRecordermonkeyrunnerMonkeyRunnerMonkeyrunner

对于MonkeyRunner,有些人可能会想,既然是Android自动化测试,离不开测试脚本,那么,我们可不可以录制测试脚本呢,答案是可以的。

我们先看看以下monkeyrecoder.py脚本:

[html] view plaincopy
  1. #Usage: monkeyrunner recorder.py
  2. #recorder.py  http://mirror.yongbok.net/linux/android/repository/platform/sdk/monkeyrunner/scripts/monkey_recorder.py
  3. com.android.monkeyrunner import MonkeyRunner as mr
  4. com.android.monkeyrunner.recorder import MonkeyRecorder as recorder
  5. device = mr.waitForConnection()
  6. recorder.start(device)
  7. #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

[html] view plaincopy
  1. #Usage: monkeyrunner playback.py "myscript"
  2. #playback.py   http://mirror.yongbok.net/linux/android/repository/platform/sdk/monkeyrunner/scripts/monkey_playback.py
  3. import sys
  4. com.android.monkeyrunner import MonkeyRunner
  5. # The format of the file we are parsing is very carfeully constructed.
  6. # Each line corresponds to a single command.  The line is split into 2
  7. # parts with a | character.  Text to the left of the pipe denotes
  8. # which command to run.  The text to the right of the pipe is a python
  9. # dictionary (it can be evaled into existence) that specifies the
  10. # arguments for the command.  In most cases, this directly maps to the
  11. # keyword argument dictionary that could be passed to the underlying
  12. # command.
  13. # Lookup table to map command strings to functions that implement that
  14. # command.
  15. CMD_MAP = {
  16. ""TOUCH"": lambda dev, arg: dev.touch(**arg),
  17. ""DRAG"": lambda dev, arg: dev.drag(**arg),
  18. ""PRESS"": lambda dev, arg: dev.press(**arg),
  19. ""TYPE"": lambda dev, arg: dev.type(**arg),
  20. ""WAIT"": lambda dev, arg: MonkeyRunner.sleep(**arg)
  21. }
  22. # Process a single file for the specified device.
  23. def process_file(fp, device):
  24. for line in fp:
  25. (cmd, rest) = line.split(""|"")
  26. try:
  27. # Parse the pydict
  28. rest = eval(rest)
  29. except:
  30. print ""unable to parse options""
  31. continue
  32. if cmd not in CMD_MAP:
  33. print ""unknown command: "" + cmd
  34. continue
  35. CMD_MAP[cmd](device, rest)
  36. def main():
  37. file = sys.argv[1]
  38. fp = open(file, ""r"")
  39. device = MonkeyRunner.waitForConnection()
  40. process_file(fp, device)
  41. fp.close();
  42. if __name__ == ""__main__"":
  43. main()

=================================================

Usage:monkeyrunner playback.py "myscript"

Android自动化测试之MonkeyRunner录制和回放脚本相关推荐

  1. Android自动化测试之MonkeyRunner MonkeyDevice MonkeyImage API使用详解 脚本编写 脚本录制回放

    MonkeyRunner 系列文章 MonkeyRunner简介 MonkeyRunner 三大模块 MonkeyRunner API MonkeyDevice API MonkeyImage API ...

  2. Android自动化测试之MonkeyRunner

    2019独角兽企业重金招聘Python工程师标准>>> MonkeyRunner是Google Android SDK下的一个工具,用于自动化测试Android程序. Monkeyr ...

  3. android 自动化测试之monkeyrunner学习(三),自动化测试之Monkeyrunner

    一.功能 Android自动化测试工具 二.环境配置 1 android-sdk 2 jdk 3 配置python环境 monkeyrunner在Android SDK的tools文件夹下 三.打开方 ...

  4. Android自动化测试之monkeyrunner基本要素(七)

    2019独角兽企业重金招聘Python工程师标准>>> 1. #导入模块;      from com.android.monkeyrunner import MonkeyRunne ...

  5. Android自动化测试之Monkey命令使用及monkey脚本编写

    系列文章 Android自动化测试环境部署及adb sdkmanager avdmanager Monitor DDMS工具使用及命令详解 Android自动化测试之Monkey使用及monkey脚本 ...

  6. [转] android自动化之MonkeyRunner测试环境配置(一)

    Android自动化测试之MonkeyRunner 一.Android自动化测试之环境搭建 1.1  Android-sdk介绍 ¢ SDK(Software development kit)软件开发 ...

  7. java appium_Android应用开发之AS+Appium+Java+Win自动化测试之Appium的Java测试脚本封装(Android测试)...

    本文将带你了解Android应用开发AS+Appium+Java+Win自动化测试之Appium的Java测试脚本封装(Android测试),希望本文对大家学Android有所帮助. 一.为什么需要封 ...

  8. 功能自动化测试之QTP录制脚本(一)

    说明:该篇博客是博主一字一码编写的,实属不易,请尊重原创,谢谢大家! 接着上一篇博客继续往下写 :https://blog.csdn.net/qq_41782425/article/details/1 ...

  9. 转 Android自动测试之monkeyrunner工具(二)

    monkeyrunner工具  前言: 最近开始研究Android自动化测试方法,对其中的一些工具.方法和框架做了一些简单的整理,其中包括android测试框架.CTS.Monkey.Monkeyru ...

最新文章

  1. Day19-File操作-创建 删除,文件过滤
  2. linux每日命令,日常整理linux常用命令大全(收藏)
  3. 1.5 测试php解析
  4. 中判断字符串是否为空_java中的数字以及如何判断字符串是不是数字
  5. Eclipse CDT Hello World工程makefile分析
  6. stata F值缺失_stata面板数据回归操作之GMM
  7. Facebook 开启元宇宙模式!豪砸百亿是为什么?
  8. 部编版是什么版本_教材部编版和人教版的区别
  9. c语言中锁的作用,C语言中的多线程死锁
  10. redis优化查询的两种方式
  11. 80-600-020-原理-存储引擎-简介
  12. Okhttp 向服务器发送请求(请求头,表单,post json数据)...
  13. Linux各个文件夹介绍
  14. busybox源码剖析(1)---whoami.c
  15. mysql_TCL语言(事务)
  16. HTML5页面实现文件下载
  17. 关于学习Java中常用类的总结
  18. 【Python】视频转换成图片
  19. Vertica的这些事(四)—— 关于vertica常用函数介绍(持续更新ing)
  20. java 正则 惰性匹配_js正则表达式惰性匹配和贪婪匹配用法分析

热门文章

  1. linux第一季运维001
  2. Ubuntu 14.04 LTS 配置 Juno 版 Keystone
  3. java内存系列:测试JDK最大内存
  4. oracle 中的几天后,几年后
  5. php 斗鱼人数,斗鱼旭旭宝宝再度登顶指数榜首位 单日弹幕人数高达48万人
  6. asp获取ftp服务器目录并显示_用 Python 快速实现 HTTP 和 FTP 服务器
  7. SpringSecurity用数据库信息做认证
  8. 使用Docker-数据卷命令
  9. ZkServer服务启动的逻辑-QuorumPeer.start
  10. 序列化技术的选型-技术层面