- 浏览: 4068004 次
文章分类
最新评论
-
klxh:
Android如何一次安装多个apk -
kchiu:
废话啊啊啊
TCP,socket 心跳检测 -
追求幸福:
iOS: 当发生signal 9为 kill的时候,程序直接被 ...
android和iOS平台的崩溃捕获和收集 -
andsy2008:
给的地址,没豆子呢,能单独发一份给我吗,andsy2008@1 ...
点餐订餐系统应用android源码 -
王粤新:
[b][i][u]引用[list]
[*][flash=200 ...
百度地图SDK for Android【事件监听】
Android自动化测试之MonkeyRunner之MonkeyDevice(八)
Android自动化测试之MonkeyRunner之MonkeyDevice
A monkeyrunner class that represents a device or emulator accessible by the workstation runningmonkeyrunner
.
This class is used to control an Android device or emulator. The methods send UI events, retrieve information, install and remove applications, and run applications.
You normally do not have to create an instance of MonkeyDevice
. Instead, you useMonkeyRunner.waitForConnection()
to create a new object from
a connection to a device or emulator. For example, instead of using:
newdevice = MonkeyDevice()
you would use:
newdevice = MonkeyRunner.waitForConnection()
Summary
string | DOWN | Use this with the type argument ofpress() ortouch() to
send a DOWN event. |
string | UP | Use this with the type argument ofpress() ortouch() to
send an UP event. |
string | DOWN_AND_UP | Use this with the type argument ofpress() ortouch() to
send a DOWN event immediately followed by an UP event. |
<nobr>void </nobr> |
<nobr><span class="sympad"><a href="http://developer.android.com/tools/help/MonkeyDevice.html#broadcastIntent">broadcastIntent</a></span>(<em>string</em> uri,<em>string</em> action,<em>string</em> data,<em>string</em> mimetype,<em>iterable</em>
categories<em>dictionary</em> extras,<em>component</em> component,<em>iterable</em> flags)</nobr> Broadcasts an Intent to this device, as if the Intent were coming from an application.
|
<nobr>void </nobr> |
<nobr><span class="sympad"><a href="http://developer.android.com/tools/help/MonkeyDevice.html#drag">drag</a></span>(<em>tuple</em> start,<em>tuple</em> end,<em>float</em> duration,<em>integer</em> steps)</nobr> Simulates a drag gesture (touch, hold, and move) on this device's screen.
|
<nobr><em>object</em> </nobr> |
<nobr><span class="sympad"><a href="http://developer.android.com/tools/help/MonkeyDevice.html#getProperty">getProperty</a></span>(<em>string</em> key)</nobr> Given the name of a system environment variable, returns its value for this device. The available variable names are listed in thedetailed description
of this method.
|
<nobr><em>object</em> </nobr> |
<nobr><span class="sympad"><a href="http://developer.android.com/tools/help/MonkeyDevice.html#getSystemProperty">getSystemProperty</a></span>(<em>string</em> key)</nobr> . The API equivalent of
adb shell getprop <key>. This is provided for use by platform developers.
|
<nobr>void </nobr> |
<nobr><span class="sympad"><a href="http://developer.android.com/tools/help/MonkeyDevice.html#installPackage">installPackage</a></span>(<em>string</em> path)</nobr> Installs the Android application or test package contained in packageFile onto this device. If the application or test package is already installed, it is replaced.
|
<nobr><em>dictionary</em> </nobr> |
<nobr><span class="sympad"><a href="http://developer.android.com/tools/help/MonkeyDevice.html#instrument">instrument</a></span>(<em>string</em> className,<em>dictionary</em> args)</nobr> Runs the specified component under Android instrumentation, and returns the results in a dictionary whose exact format is dictated by the component being run. The component must already be present on this device.
|
<nobr>void </nobr> |
<nobr><span class="sympad"><a href="http://developer.android.com/tools/help/MonkeyDevice.html#press">press</a></span>(<em>string</em> name,<em>dictionary</em> type)</nobr> Sends the key event specified by type to the key specified by keycode.
|
<nobr>void </nobr> |
<nobr><span class="sympad"><a href="http://developer.android.com/tools/help/MonkeyDevice.html#reboot">reboot</a></span>(<em>string</em> into)</nobr> Reboots this device into the bootloader specified by bootloadType.
|
<nobr>void </nobr> |
<nobr><span class="sympad"><a href="http://developer.android.com/tools/help/MonkeyDevice.html#removePackage">removePackage</a></span>(<em>string</em> package)</nobr> Deletes the specified package from this device, including its data and cache.
|
<nobr><em>object</em> </nobr> |
<nobr><span class="sympad"><a href="http://developer.android.com/tools/help/MonkeyDevice.html#shell">shell</a></span>(<em>string</em> cmd)</nobr> Executes an
adb shell command and returns the result, if any. |
<nobr>void </nobr> |
<nobr><span class="sympad"><a href="http://developer.android.com/tools/help/MonkeyDevice.html#startActivity">startActivity</a></span>(<em>string</em> uri,<em>string</em> action,<em>string</em> data,<em>string</em> mimetype,<em>iterable</em>
categories<em>dictionary</em> extras,<em>component</em> component,<em>flags</em>)</nobr> Starts an Activity on this device by sending an Intent constructed from the supplied arguments.
|
<nobr><code><a href="http://developer.android.com/tools/help/MonkeyImage.html">MonkeyImage</a></code></nobr> |
<nobr><span class="sympad"><a href="http://developer.android.com/tools/help/MonkeyDevice.html#takeSnapshot">takeSnapshot</a>()</span></nobr> Captures the entire screen buffer of this device, yielding a
MonkeyImage object containing a screen capture of the current display. |
<nobr>void </nobr> |
<nobr><span class="sympad"><a href="http://developer.android.com/tools/help/MonkeyDevice.html#touch">touch</a></span>(<em>integer</em> x,<em>integer</em> y,<em>integer</em> type)</nobr> Sends a touch event specified by type to the screen location specified by x and y.
|
<nobr>void </nobr> |
<nobr><span class="sympad"><a href="http://developer.android.com/tools/help/MonkeyDevice.html#touch">type</a></span>(<em>string</em> message)</nobr> Sends the characters contained in message to this device, as if they had been typed on the device's keyboard. This is equivalent to calling
press()
for each keycode inmessage using the key event type DOWN_AND_UP . |
<nobr>void </nobr> |
<nobr><span class="sympad"><a href="http://developer.android.com/tools/help/MonkeyDevice.html#touch">wake</a></span>()</nobr> Wakes the screen of this device.
|
Constants
string DOWN
string UP
string DOWN_AND_UP
Public Methods
void broadcastIntent(string uri,string action,string data,string mimetype,iterable categoriesdictionary extras,component component,iterable flags)
Broadcasts an Intent to this device, as if the Intent were coming from an application. SeeIntent
for more information about the arguments.
Arguments
The URI for the Intent. (see Intent.setData() ). |
The action for this Intent (see Intent.setAction() ). |
The data URI for this Intent (see Intent.setData() ). |
The MIME type for the Intent (see Intent.setType() ). |
An iterable data structure containing strings that define categories for this Intent (seeIntent.addCategory() ). |
A dictionary of extra data for this Intent (see Intent.putExtra() for an example).
The key for each dictionary item should be a string. The item's value can be any simple or structured data type. |
The component for this Intent (see ComponentName ). Using this argument will direct the Intent to a specific class within a specific Android package. |
An iterable data structure containing flags that control how the Intent is handled (seeIntent.setFlags() ). |
void drag(tuple start,tuple end,float duration,integer steps)
Simulates a drag gesture (touch, hold, and move) on this device's screen.
Arguments
The starting point of the drag gesture, in the form of a tuple (x,y) where x and y areintegers. |
The end point of the drag gesture, in the form of a tuple (x,y) where x and y areintegers. |
The duration of the drag gesture in seconds. The default is 1.0 seconds. |
The number of steps to take when interpolating points. The default is 10. |
object getProperty(string key)
Given the name of a system environment variable, returns its value for this device.
Arguments
The name of the system environment variable. The available variable names are listed inTable 1. Property variable names at the end of this topic. |
Returns
- The value of the variable. The data format varies according to the variable requested.
object getSystemProperty(string key)
Synonym for getProperty()
.
Arguments
The name of the system environment variable. The available variable names are listed inTable 1. Property Variable Names. |
Returns
- The value of the variable. The data format varies according to the variable requested.
void installPackage(string path)
Installs the Android application or test package contained in packageFile onto this device. If the application or test package is already installed, it is replaced.
Arguments
The fully-qualified path and filename of the .apk file to install. |
dictionary instrument(string className,dictionary args)
Runs the specified component with Android instrumentation, and returns the results in a dictionary whose exact format is dictated by the component being run. The component must already be present on this device.
Use this method to start a test case that uses one of Android's test case classes. SeeTesting Fundamentals to learn more about unit testing with the Android testing framework.
Arguments
The name of an Android component that is already installed on this device, in the standard form packagename/classname, where packagename is the Android package name of a.apk file on this device, and classname is the class name of an Android
component (Activity, ContentProvider, Service, or BroadcastReceiver) in that file. Both packagename and classname must be fully qualified. SeeComponentName
for more details. |
A dictionary containing flags and their values. These are passed to the component as it is started. If the flag does not take a value, set its dictionary value to an empty string. |
Returns
-
A dictionary containing the component's output. The contents of the dictionary are defined by the component itself.
If you use
InstrumentationTestRunner
as the class name in the componentName argument, then the result dictionary contains the single key "stream". The value of "stream" is a string containing the test output, as ifInstrumentationTestRunner
was run from the command line. The format of this output is described inTesting in Other IDEs.
void press(string name,integer type)
Sends the key event specified by type
to the key specified by
keycode
.
Arguments
The name of the keycode to send. See KeyEvent for a list of keycode names. Use the keycode name, not its integer value. |
The type of key event to send. The allowed values are DOWN ,UP ,
andDOWN_AND_UP . |
void reboot(string bootloadType)
Reboots this device into the bootloader specified by bootloadType
.
Arguments
The type of bootloader to reboot into. The allowed values are "bootloader", "recovery", or "None". |
void removePackage(string package)
Deletes the specified package from this device, including its data and cache.
Arguments
The Android package name of an .apk file on this device. |
object shell(string cmd)
Executes an adb
shell command and returns the result, if any.
Arguments
The command to execute in the adb shell. The form of these commands is described in the topicAndroid Debug Bridge. |
Returns
- The results of the command, if any. The format of the results is determined by the command.
void startActivity(string uri,string action,string data,string mimetype,iterable categoriesdictionary extras,component component,iterable flags)
Starts an Activity on this device by sending an Intent constructed from the supplied arguments.
Arguments
The URI for the Intent. (see Intent.setData() ). |
The action for the Intent (see Intent.setAction() ). |
The data URI for the Intent (see Intent.setData() ). |
The MIME type for the Intent (see Intent.setType() ). |
An iterable data structure containing strings that define categories for the Intent (seeIntent.addCategory() ). |
A dictionary of extra data for the Intent (see Intent.putExtra() for an example).
The key for each dictionary item should be a string. The item's value can be any simple or structured data type. |
The component for the Intent (see ComponentName ). Using this argument will direct the Intent to a specific class within a specific Android package. |
An iterable data structure containing flags that control how the Intent is handled (seeIntent.setFlags() ). |
MonkeyImage
takeSnapshot()
Captures the entire screen buffer of this device, yielding a screen capture of the current display.
Returns
- A MonkeyImage object containing the image of the current display.
void touch(integer x,integer y,string type)
Sends a touch event specified by type to the screen location specified by x and y.
Arguments
The horizontal position of the touch in actual device pixels, starting from the left of the screen in its current orientation. |
The vertical position of the touch in actual device pixels, starting from the top of the screen in its current orientation. |
The type of key event to send. The allowed values are DOWN ,UP ,
andDOWN_AND_UP . |
void type(string message)
Sends the characters contained in message to this device, as if they had been typed on the device's keyboard. This is equivalent to callingpress()
for each keycode
inmessage
using the key event type DOWN_AND_UP
.
Arguments
A string containing the characters to send. |
void wake()
Wakes the screen of this device.
参考:http://developer.android.com/tools/help/MonkeyDevice.html
相关推荐
android自动化测试monkeyrunner的入门使用教程,讲解了如何使用monkeyrunner进行android的自动化测试
Android自动化测试(MonkeyRunner)脚本
Android自动化测试之MonkeyRunner--从环境构建、参数讲解、脚本制作到实战技巧
Android自动化测试之Monkeyrunner常用操作编程 本篇乃本人学习monkeyrunner时笔记,查看网络中的资料并经本人测试而出,由于本人刚接触,所以本篇内容不免肤浅,高手们请绕走~ 在测试本人以下实例时,请自行搭建...
该文档包含了本人对android自动化测试工具monkeyrunner的一些总结,有需要的可以看看。
详细介绍了如何搭建Android自动化测试环境以及使用Monkeyrunner进行自动化测试的方法。
Android自动测试之monkeyrunner工具.docxAndroid自动测试之monkeyrunner工具.docx
monkeyrunner工具提供一个API来控制Android设备。可以写一个python脚本来安装应用,运行应用,发送键值,截图。monkeyrunner对python进行了封装,加入了一些针对Android设备的类。可以完全用python脚本来实现这些...
本文主要通过PPT的方式来介绍APP自动化相关知识,并且以MonKeyRunner为例讲解如何通过MonKeyRunner实战操作自动化测试
3.Create_Android_Sample_App 4.Test_Android_Sample_App Android手机测试方法交流 ...Android自动化测试之道 GSM手机自动化测试解决方案 手机自动化测试系统设计浅析 在Android_Robotium自动化测试中导出Test_result
知识共享-Android自动测试之monkeyrunner工具(雷惊风).
该文档适用于android平台项目的软件自动化测试,本文档描述了Monkeyrunner环境配置和具体使用教程,可供学习
非扫描版 带书签许奔 著ISBN:978-7-111-52120-4目录本书赞誉前言第一部分 基础篇第1章 Android自动化测试基础1.1 Android自动化分析1.2 什么样的兵器最称手1.3 如何耍好你手上的兵器1.4 你了解你的兵器吗1.5...
用于测试Android计算器,适合初学monkeyrunner测试脚本编写者
Android UiAutomator 自动化测试原理 1、Android自动化工具简介 2、环境安装配置 3、测试原理及案例 4、其它注意事项 Android官方自动化测试工具 基于python Monkey是Android SDK自带的测试工具 MonkeyRunner也是...
NULL 博文链接:https://myeyeofjava.iteye.com/blog/1561738
比较了monkeyrunner和monkey这两个好兄弟,同时把monkeyrunner实现的脚本集成到eclipse-pydev的环境中运行
前言:最近开始研究Android自动化测试方法,对其中的一些工具、方法和框架做了一些简单的整理,其中包括android测试框架、CTS、Monkey、Monkeyrunner、benchmark、其它testtool等等。因接触时间很短,很多地方有不足...
最近研究了一下android的自动化测试工具,其中用的比较多的就是google开源自带的monkeyrunner,还有一个就是robotium工具。文档是在eclipse中添加python和robotium插件的配置环境说明,方便使用monkeyrunner或是...