【金阳光测试】Android自动化 -- 学习历程:Monkey原理初步和改良优化

章节:自动化基础篇——Monkey原理初步和改良优化(第三讲)

网易云课堂:

http://study.163.com/course/courseLearn.htm?courseId=712011#/learn/video?lessonId=878100&courseId=712011

主要讲解内容与笔记:

一、理论知识:

直接看文档,来了解monkey的概念、基本原理,以及如何使用。

First,what is Android Monkey?

The Monkey is a program that runs on your emulator or device and generates pseudo-random streams of user events such as clicks, touches, or gestures, as well as a number of system-level events. You can use the Monkey to stress-test applications that you are developing, in a random yet repeatable manner.

翻译过来:Monkey 是一个可以运行在模拟器或设备上的程序,它可以生成用户时间的伪随机序列,如点击,触屏,或者抓取,也包含一系列的系统级的事件。我们可以使用Monkey对自己开发的应用程序做压力测试,使用随机且可重复的操作。

注:说明一下什么是伪随机事件?

所谓伪随机事件,就是:seed相同,则随机序列不变;并且在一定时间内,所生成的随机事件不重复。

Second,what can Monkey do?

The Monkey is a command-line tool that that you can run on any emulator instance or on a device. It sends a pseudo-random stream of user events into the system, which acts as a stress test on the application software you are developing.

The Monkey includes a number of options, but they break down into four primary categories:

  • Basic configuration options, such as setting the number of events to attempt.
  • Operational constraints, such as restricting the test to a single package.
  • Event types and frequencies.
  • Debugging options.

When the Monkey runs, it generates events and sends them to the system. It also watches the system under test and looks for three conditions, which it treats specially:

  • If you have constrained the Monkey to run in one or more specific packages, it watches for attempts to navigate to any other packages, and blocks them.
  • If your application crashes or receives any sort of unhandled exception, the Monkey will stop and report the error.
  • If your application generates an application not responding error, the Monkey will stop and report the error.

Depending on the verbosity level you have selected, you will also see reports on the progress of the Monkey and the events being generated.

翻译过来:

Monkey包含多种选择,但是它们分为以下四种基本部分:

  • 基础设置选项,如设置将做事件的数目
  • 操作限制,如限制某个单一包的测试
  • 事件类型和频率
  • 调试选项

当Monkey跑起来之后,就会产生事件,并将它们发送到系统。它也会关注测试下的系统情况,注意一下的三种情况会被特殊对待哦:

  • 如果你限制了Monkey只能泡在某一个或更多个特定的包上时,它就会关注打算去跨越到其他包的企图,并阻止它们。
  • 如果你的应用程序崩掉了或者接受到了其他种类的不可控异常,Monkey就会停掉,并report这个Error
  • 如果你的应用程序生成了一个不发送error的应用,Monkey也会阻止并report这个Error

Third,how to use Monkey?

The basic syntax is:

$ adb shell monkey [options] <event-count>

一般大家比较简单的就这样用:

$ adb shell monkey -p your.package.name -v 500

接下来重点介绍命令行参数的含义:

Category Option Description
General --help Prints a simple usage guide.
-v Each -v on the command line will increment the verbosity level. Level 0 (the default) provides little information beyond startup notification, test completion, and final results. Level 1 provides more details about the test as it runs, such as individual events being sent to your activities. Level 2 provides more detailed setup information such as activities selected or not selected for testing.
Events -s <seed> Seed value for pseudo-random number generator. If you re-run the Monkey with the same seed value, it will generate the same sequence of events.
--throttle <milliseconds> Inserts a fixed delay between events. You can use this option to slow down the Monkey. If not specified, there is no delay and the events are generated as rapidly as possible.
--pct-touch <percent> Adjust percentage of touch events. (Touch events are a down-up event in a single place on the screen.)
--pct-motion <percent> Adjust percentage of motion events. (Motion events consist of a down event somewhere on the screen, a series of pseudo-random movements, and an up event.)
--pct-trackball <percent> Adjust percentage of trackball events. (Trackball events consist of one or more random movements, sometimes followed by a click.)
--pct-nav <percent> Adjust percentage of "basic" navigation events. (Navigation events consist of up/down/left/right, as input from a directional input device.)
--pct-majornav <percent> Adjust percentage of "major" navigation events. (These are navigation events that will typically cause actions within your UI, such as the center button in a 5-way pad, the back key, or the menu key.)
--pct-syskeys <percent> Adjust percentage of "system" key events. (These are keys that are generally reserved for use by the system, such as Home, Back, Start Call, End Call, or Volume controls.)
--pct-appswitch <percent> Adjust percentage of activity launches. At random intervals, the Monkey will issue a startActivity() call, as a way of maximizing coverage of all activities within your package.
--pct-anyevent <percent> Adjust percentage of other types of events. This is a catch-all for all other types of events such as keypresses, other less-used buttons on the device, and so forth.
Constraints -p <allowed-package-name> If you specify one or more packages this way, the Monkey will only allow the system to visit activities within those packages. If your application requires access to activities in other packages (e.g. to select a contact) you‘ll need to specify those packages as well. If you don‘t specify any packages, the Monkey will allow the system to launch activities in all packages. To specify multiple packages, use the -p option multiple times — one -p option per package.
-c <main-category> If you specify one or more categories this way, the Monkey will only allow the system to visit activities that are listed with one of the specified categories. If you don‘t specify any categories, the Monkey will select activities listed with the category Intent.CATEGORY_LAUNCHER or Intent.CATEGORY_MONKEY. To specify multiple categories, use the -c option multiple times — one -c option per category.
Debugging --dbg-no-events When specified, the Monkey will perform the initial launch into a test activity, but will not generate any further events. For best results, combine with -v, one or more package constraints, and a non-zero throttle to keep the Monkey running for 30 seconds or more. This provides an environment in which you can monitor package transitions invoked by your application.
--hprof If set, this option will generate profiling reports immediately before and after the Monkey event sequence. This will generate large (~5Mb) files in data/misc, so use with care. See Traceview for more information on trace files.
--ignore-crashes Normally, the Monkey will stop when the application crashes or experiences any type of unhandled exception. If you specify this option, the Monkey will continue to send events to the system, until the count is completed.
--ignore-timeouts Normally, the Monkey will stop when the application experiences any type of timeout error such as a "Application Not Responding" dialog. If you specify this option, the Monkey will continue to send events to the system, until the count is completed.
--ignore-security-exceptions Normally, the Monkey will stop when the application experiences any type of permissions error, for example if it attempts to launch an activity that requires certain permissions. If you specify this option, the Monkey will continue to send events to the system, until the count is completed.
--kill-process-after-error Normally, when the Monkey stops due to an error, the application that failed will be left running. When this option is set, it will signal the system to stop the process in which the error occurred. Note, under a normal (successful) completion, the launched process(es) are not stopped, and the device is simply left in the last state after the final event.
--monitor-native-crashes Watches for and reports crashes occurring in the Android system native code. If --kill-process-after-error is set, the system will stop.
--wait-dbg Stops the Monkey from executing until a debugger is attached to it.

二、Monkey架构原理初步

三、改良Monkey方案1(只点击你需要点的地方):做java工程,adb push进去

四、优化Monkey方案2(脱离adb口控制):做成android apk形式,让系统级进程直接调用它

时间: 2024-10-13 01:51:03

【金阳光测试】Android自动化 -- 学习历程:Monkey原理初步和改良优化的相关文章

Monkey原理初步和改良优化--Android自动化测试学习历程

章节:自动化基础篇——Monkey原理初步和改良优化(第三讲) 主要讲解内容与笔记: 一.理论知识: 直接看文档,来了解monkey的概念.基本原理,以及如何使用. First,what is Android Monkey? The Monkey is a program that runs on your emulator or device and generates pseudo-random streams of user events such as clicks, touches,

【金阳光测试】Android自动化 -- 学习历程:Robotium原理初步

章节:自动化基础篇——Monkey原理初步和改良优化(第四讲) 网易云课堂: http://study.163.com/course/courseLearn.htm?courseId=712011#/learn/video?lessonId=876095&courseId=712011 主要讲解内容与笔记: 一.基于控件 1.spinner——下拉菜单 2.TabHost——左右滑动选择菜单,类似电话本 3.Gallery——图形 4.Progressbar——进度条 5.DatePicker—

【金阳光测试】Android自动化 -- 学习历程:MonkeyRunner原理初步

章节:自动化基础篇——MonkeyRunner原理初步 网易云课堂: http://study.163.com/course/courseLearn.htm?courseId=712011#/learn/video?lessonId=877115&courseId=712011 主要讲解内容及笔记: 一.理论知识和脚本演示 最佳方式是上官网文档去查看monkeyrunner的介绍,官网上不去,就找了一个本地的android 4.2 的查看,基本内容没啥变化 First,什么是MonkeyRunn

【金阳光测试】Android自动化 -- 学习历程:百度Cafe原理

章节:自动化基础篇——百度Cafe原理初步(第八讲) 金阳光测试官网: http://www.goldensunshine.cc/forum.php?mod=viewthread&tid=20&extra=page%3D2 主要讲解内容及笔记: 一.Cafe原理 Cafe是一款自动化测试框架,解决问题:跨进程测试.快速深度测试 官网:http://baiduqa.github.io/Cafe/ Cafe provides the following benefits: * You can

【金阳光测试】Android自动化 -- 学习历程:AndroidDriver原理初步

章节:自动化基础篇——AndroidDriver原理初步(第六讲) 网易云课堂: http://study.163.com/course/courseLearn.htm?courseId=712011#/learn/video?lessonId=877116&courseId=712011 主要讲解内容及笔记: 一.AndroidDriver核心原理 对上图的解析: PC端的端口通过adb,将android版的Remote Server的apk push到手机上,然后跟手机端的Remote Se

【金阳光测试】Android自动化 -- 学习历程:Appium原理初步

章节:自动化基础篇——Appium原理初步(第七讲) 金阳光测试官网: http://www.goldensunshine.cc/forum.php?mod=viewthread&tid=19&extra=page%3D2 本期关键词: Appium.跨语言跨平台.Bootstrap 主要讲解内容及笔记: 一.what is appium 一种封装了uiautomator.或者其他测试框架的自动化测试框架,跨平台(支持linux.mac.windows).跨语言(几乎所有的我知道的语言都支

【金阳光测试】Android自动化 -- 学习历程:Selenium原理初步

章节:自动化基础篇——Selenium原理初步(第五讲) 网易云课堂: http://study.163.com/course/courseLearn.htm?courseId=712011#/learn/video?lessonId=878101&courseId=712011 注:其实所有的东西都是应该先去用,但是工具基本都一样,底层都是用的最基础的内容实现的,测试应该做的是: (1)熟练使用工具,了解各个工具的利弊,达到工具优选.因时因地制宜的目的 (2)读源码,理解原理,能够对开源的源码

Selenium原理初步--Android自动化测试学习历程

章节:自动化基础篇——Selenium原理初步(第五讲) 注:其实所有的东西都是应该先去用,但是工具基本都一样,底层都是用的最基础的内容实现的,测试应该做的是: (1)熟练使用工具,了解各个工具的利弊,达到工具优选.因时因地制宜的目的 (2)读源码,理解原理,能够对开源的源码进行二次再创造,改编成适合自身产品的工具:或者自己直接编写适合测试的工具 (3)能够对测试过程中发生的异常进行分析和定位,对测试结果进行详细和系统的综合评定(需要能够分析定位问题,必须对自身产品了解,但更需要的是对底层代码和

Robotium原理初步--Android自动化测试学习历程

章节:自动化基础篇——Robotium原理初步(第四讲) 主要讲解内容与笔记: 一.基于控件 1.spinner——下拉菜单 2.TabHost——左右滑动选择菜单,类似电话本 3.Gallery——图形 4.Progressbar——进度条 5.DatePicker——日期与时间选择控件 6.CheckBox——单选框:RadioButton——互斥单选框:Button——一般按钮 7.ToggleButton——双状态按钮控件:选择和未选择两种状态,并且针对不同状态显示不同文本8.EditT