monkeyrunner
The monkeyrunner tool provides an API for writing programs that control an Android device or emulator from outside of Android code. With monkeyrunner, you can write a Python program that installs an Android application or test package, runs it, sends keystrokes to it, takes screenshots of its user interface, and stores screenshots on the workstation. The monkeyrunner tool is primarily designed to test applications and devices at the functional/framework level and for running unit test suites, but you are free to use it for other purposes.
Monkeyrunner工具为程序提供了可以从安卓代码之外的方式控制安卓设备或者模拟器的API.通过monkeyrunner,你能用python编程,安装安卓应用或者测试包,运行它,发送按键给它,从UI上截图,并且把截图存到工作站上.monkeyrunner工具主要设计用来在功能或者框架层级测试程序和设备并用来运行单元测试套件,但是你可以为了其他目的随便使用.
The monkeyrunner tool is not related to the UI/Application Exerciser Monkey, also known as the monkey
tool. The monkey
tool runs in an adb
shell directly on the device or emulator and generates pseudo-random streams of user and system events. In comparison, the monkeyrunner tool controls devices and emulators from a workstation by sending specific commands and events from an API.
monkeyrunner工具与monkey工具没有关系,尽管都有monkey这个字. Monkey 工具在ADB shell中直接运行在设备和模拟器上并生成用户伪随机事件流和系统事件.为了对比,monkeyrunner 工具通过从工作站上发送指定API中的命令和事件控制设备和模拟器.
The monkeyrunner tool provides these unique features for Android testing:
monkeyrunner 工具为安卓测试提供了以下这些独特功能:
- Multiple device control: The monkeyrunner API can apply one or more test suites across multiple devices or emulators. You can physically attach all the devices or start up all the emulators (or both) at once, connect to each one in turn programmatically, and then run one or more tests. You can also start up an emulator configuration programmatically, run one or more tests, and then shut down the emulator.
多设备控制: monkeyrunner API能应用跨多个设备和模拟器应用一个或多个测试套件.你能在物理上一次连上所有设备和启动所有的模拟器,依照程序依次连接,并且运行一个或多个测试.你也能启动配置好的模拟器,运行一个或多个测试并且关掉模拟器.
- Functional testing: monkeyrunner can run an automated start-to-finish test of an Android application. You provide input values with keystrokes or touch events, and view the results as screenshots.
功能测试: monkeyrunner能为安卓应用运行自动的从开始到结束的测试.你能输入按键或者触摸事件的值并从截图上看到结果.
- Regression testing - monkeyrunner can test application stability by running an application and comparing its output screenshots to a set of screenshots that are known to be correct.
回归测试: monkeyrunner 能通过运行应用和对比运行结果截图与正确截图测试程序稳定性.
- Extensible automation - Since monkeyrunner is an API toolkit, you can develop an entire system of Python-based modules and programs for controlling Android devices. Besides using the monkeyrunner API itself, you can use the standard Python
os
andsubprocess
modules to call Android tools such as Android Debug Bridge.You can also add your own classes to the monkeyrunner API. This is described in more detail in the section Extending monkeyrunner with plugins.
可扩展的自动化工具. 因为monkeyrunner是一个API工具包,你能基于python modules和安卓控制程序开发一个完整系统.除了使用monkeyrunner本身的API,你也能使用python os 和subprocess 模块调用安卓工具,例如 android debug brige.
你也能添加你自己的类去monkeyrunner 的API, 这个更多的介绍在Extending monkeyrunner with plugins.
The monkeyrunner tool uses Jython, a implementation of Python that uses the Java programming language. Jython allows the monkeyrunner API to interact easily with the Android framework. With Jython you can use Python syntax to access the constants, classes, and methods of the API.
monkeyrunner 工具使用Jython, 一种用JAVA实现的Python语言.Jython 允许monkeyrunner的API与安卓框架更容易的交互. 用Jython 你能用python的语法去连接常量,类,和API中的方法.