




已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
monkeyrunnerIn this document1. A Simple monkeyrunner Program 2. The monkeyrunner API 3. Running monkeyrunner 4. monkeyrunner Built-in Help 5. Extending monkeyrunner with Plugins See Also1. Testing Fundamentals 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. 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. The monkeyrunner tool provides these unique features for Android testing: 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. 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. 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. 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 and subprocess 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. 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. A Simple monkeyrunner ProgramHere is a simple monkeyrunner program that connects to a device, creating a MonkeyDevice object. Using the MonkeyDevice object, the program installs an Android application package, runs one of its activities, and sends key events to the activity. The program then takes a screenshot of the result, creating a MonkeyImage object. From this object, the program writes out a .png file containing the screenshot. # Imports the monkeyrunner modules used by this programfrom com.android.monkeyrunner import MonkeyRunner, MonkeyDevice# Connects to the current device, returning a MonkeyDevice objectdevice = MonkeyRunner.waitForConnection()# Installs the Android package. Notice that this method returns a boolean, so you can test# to see if the installation worked.device.installPackage(myproject/bin/MyApplication.apk)# Runs an activity in the applicationdevice.startActivity(component=com.example.android.myapplication.MainActivity)# Presses the Menu buttondevice.press(KEYCODE_MENU,DOWN_AND_UP)# Takes a screenshotresult = device.takeSnapShot# Writes the screenshot to a fileresult.writeToFile(myproject/shot1.png,png)The monkeyrunner APIThe monkeyrunner API is contained in three modules in the package com.android.monkeyrunner: l MonkeyRunner: A class of utility methods for monkeyrunner programs. This class provides a method for connecting monkeyrunner to a device or emulator. It also provides methods for creating UIs for a monkeyrunner program and for displaying the built-in help. l MonkeyDevice: Represents a device or emulator. This class provides methods for installing and uninstalling packages, starting an Activity, and sending keyboard or touch events to an application. You also use this class to run test packages. l MonkeyImage: Represents a screen capture image. This class provides methods for capturing screens, converting bitmap images to various formats, comparing two MonkeyImage objects, and writing an image to a file. In a Python program, you access each class as a Python module. The monkeyrunner tool does not import these modules automatically. To import a module, use the Python from statement: from com.android.monkeyrunner import where is the class name you want to import. You can import more than one module in the same from statement by separating the module names with commas. Running monkeyrunnerYou can either run monkeyrunner programs from a file, or enter monkeyrunner statements in an interactive session. You do both by invoking the monkeyrunner command which is found in the tools/ subdirectory of your SDK directory. If you provide a filename as an argument, the monkeyrunner command runs the files contents as a Python program; otherwise, it starts an interactive session. The syntax of the monkeyrunner command is monkeyrunner -plugin Table 1 explains the flags and arguments. Table 1. monkeyrunner flags and arguments.ArgumentDescription-plugin (Optional) Specifies a .jar file containing a plugin for monkeyrunner. To learn more about monkeyrunner plugins, see Extending monkeyrunner with plugins. To specify more than one file, include the argument multiple times. If you provide this argument, the monkeyrunner command runs the contents of the file as a Python program. If the argument is not provided, the command starts an interactive session. (Optional) Flags and arguments for the program in . monkeyrunner Built-in HelpYou can generate an API reference for monkeyrunner by running: monkeyrunner help.py The arguments are: l is either text for plain text output or html for HTML output. l is a path-qualified name for the output file. Extending monkeyrunner with PluginsYou can extend the monkeyrunner API with classes you write in the Java programming language and build into one or more .jar files. You can use this feature to extend the monkeyrunner API with your own classes or to extend the existing classes. You can also use this feature to initialize the monkeyrunner environment. To provide a plugin to monkeyrunner, invoke the monkeyrunner command with the -plugin argument described in table 1. In your plugin code, you can import and extend the the main monkeyrunner classes MonkeyDevice, MonkeyImage, and MonkeyRunner in com.android.monkeyrunner (see The monkeyrunner API). Note that plugins do not give you access to the Android SDK. You cant import packages such as com.android.app. This is because monkeyrunner interacts with the device or emulator below the level of the framework APIs. The plugin startup classThe .jar file for a plugin can specify a class that is instantiated before script processing starts. To specify this class, add the key MonkeyRunnerStartupRunner to the .jar files manifest. The value should be the name of the class to run at startup. The following snippet shows how you would do this within an ant build script: To ge
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年燃气储运中级工程师面试要点及模拟题详解
- 眼外伤的护理课件
- 2025年人力资源专员求职面试指南与模拟题解析
- 2025年电力行业运行值班员中级考试面试题及答案
- 2025年低温巴氏乳项目提案报告模板
- 2025年星巴克项目规划申请报告
- 看护业务知识培训课件
- 2025年色淀红类项目规划申请报告模板
- 2025年海洋资料浮标项目立项申请报告模板
- 布病护理课件
- 危险化学品应急演练计划
- 2025-2030中国催化裂化催化剂行业前景展望及需求趋势预测报告
- 电厂设备清洁管理制度
- 左上颌骨囊肿护理查房
- 公司六一活动家属开放日活动方案
- 2025至2030年中国继电保护及自动化设备行业市场现状调查及发展趋向研判报告
- 2025年重庆市中考数学试卷真题及答案详解(精校打印版)
- 关于医院“十五五”发展规划(2026-2030)
- 民航气象专业面试题及答案
- 浙江仙琚制药股份有限公司年产2.5亿粒性激素软胶囊生产线技术改造项目环评报告
- DB37/T 3658-2019地质灾害治理工程施工技术规范
评论
0/150
提交评论