A monkeyrunner class that represents a device or emulator accessible by the workstation running monkeyrunner.

monkeyrunner类代表了能被工作站运行monkeyrunner连接的设备或者模拟器

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.

这个类通常用来控制安卓设备或者模拟器. 这个方法包括,发送UI事件,检索信息,安卓或者下载程序,和运行程序.

You normally do not have to create an instance of MonkeyDevice. Instead, you use MonkeyRunner.waitForConnection() to create a new object from a connection to a device or emulator. For example, instead of using:

通常你不需要单独去创建一个monkeydevice的实例, 你可以用MonkeyRunner.waitForConnection()创建一个对象连接设备和模拟器.例如,通常不用

newdevice = MonkeyDevice()

you would use:

而使用:

newdevice = MonkeyRunner.waitForConnection()

Constants

string DOWN

press() or touch() value. Specifies that a DOWN event type should be sent to the device, corresponding to pressing down on a key or touching the screen.

press() 或者touch()的值.指定一个DOWN事件类型发送给设备,相当于按下一个按键或者触摸屏幕.

string UP

press() or touch() value. Specifies that an UP event type should be sent to the device, corresponding to releasing a key or lifting up from the screen.

press() 或者touch()的值.指定一个UP事件类型发送给设备,相当于释放一个按键或者离开屏幕.

string DOWN_AND_UP

press(), touch() or type() value. Specifies that a DOWN event type followed by an UP event type should be sent to the device, corresponding to typing a key or clicking the screen.

press(),touch() 或者 type()的值. 指定一个down事件类型跟随一个UP事件类型发送给设备,相当于点击一个按键或者点击屏幕.

Public Methods

void broadcastIntent ( string uri, string action, string data, string mimetype, iterable categories dictionary extras, component component, iterable flags) ?

  Broadcasts an Intent to this device, as if the Intent were coming from an application. See Intent for more information about the arguments.

  对设备广播Intent, 就像这个Intent是从程序来的.

  Arguments

    uri  The URI for the Intent. (see Intent.setData()).

    action  The action for this Intent (see Intent.setAction()).

    data    The data URI for this Intent (see Intent.setData()).

    mimetype  The MIME type for the Intent (see Intent.setType()).

    categories An iterable data structure containing strings that define categories for this Intent (see             Intent.addCategory()).

    extras  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.

    component      The component for this Intent (see ComponentName). Using this argument will direct             the Intent to a specific class within a specific Android package.

    flags    An iterable data structure containing flags that control how the Intent is handled (see             Intent.setFlags()).

void drag ( tuple start, tuple end, float duration, integer steps) ?

  Simulates a drag gesture (touch, hold, and move) on this device's screen.

  在屏幕上模拟一个drag的手势(触摸,保持并且移动)

Arguments

  start          The starting point of the drag gesture, in the form of a tuple (x,y) where x and y are integers.

          drag手势开始的点,用元组(x,y)表示, x,y是整数.

  end      The end point of the drag gesture, in the form of a tuple (x,y) where x and y are integers.

          drag手势结束的点,用元组(x,y)表示, x,y是整数.

  duration    The duration of the drag gesture in seconds. The default is 1.0 seconds.

          drag手势的时间,默认是1秒.

  steps         The number of steps to take when interpolating points. The default is 10.

           插值点时要采用的步骤.默认是10.

object getProperty (string key)

  Given the name of a system environment variable, returns its value for this device.

  给出系统环境变量,返回设备值.

  Arguments

    key   The name of the system environment variable. The available variable names are listed in "Table 1. Property variable names" at the end of this           topic.

        系统环境变量的名字. 可用的变量名字在Topic最后的Table1列出.

    Returns

      The value of the variable. The data format varies according to the variable requested.

        返回变量的值, 数据格式依据需求变化.

object getSystemProperty (string key)

  Synonym for getProperty().

  和getProperty()同义.

  Arguments

    key   The name of the system environment variable. The available variable names are listed in Table 1. Property Variable Names.

        系统环境变量的名字. 可用的变量名字在Topic最后的Table1列出.

    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

    path   The fully-qualified path and filename of the .apk file to install.

          全路径.apk的包名.

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. See Testing         Fundamentals to learn more about unit testing with      the Android testing framework.

  Arguments

    className      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. See ComponentName for              more details.

    args      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 if InstrumentationTestRunner was run from the command line. The format of this output is described in Testing in Other IDEs.

void press (string name, integer type)

  Sends the key event specified by type to the key specified by keycode.

  发送一个指定类型的key 事件

  Arguments

    name        The name of the keycode to send. See KeyEvent for a list of keycode names. Use the keycode name, not its integer value.

            要发送的keycode的名字. 要使用keycode的名字,不用数值,(http://developer.android.com/reference/android/view/KeyEvent.html)

    type    The type of key event to send. The allowed values are DOWN, UP, and DOWN_AND_UP.

           要发送的KEY事件的类型. 允许的值为DOWN, UP 和 DOWN_AND_UP

void reboot (string bootloadType)

  Reboots this device into the bootloader specified by bootloadType.

  重启设备进入到bootloader

  Arguments

    into  The type of bootloader to reboot into. The allowed values are "bootloader", "recovery", or           "None".

        重启后进入bootloader的类型, 允许的值为"bootloader", "recovery" 或者 "None".

void removePackage (string package)

  Deletes the specified package from this device, including its data and cache.

  从设备上删除指定的包,包括数据和缓存.

  Arguments

    package   The Android package name of an .apk file on this device.

          一个.apk的包名.

object shell (string cmd)

  Executes an adb shell command and returns the result, if any.

  执行一个adb shell的命令并返回结果.

  Arguments

    cmd   The command to execute in the adb shell. The form of these commands is described in the topic Android Debug Bridge.

          要再adb shell中执行的命令. (http://developer.android.com/tools/help/adb.html)

    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 categories dictionary extras, component component, iterable flags)

  Starts an Activity on this device by sending an Intent constructed from the supplied arguments.

  Arguments

    uri    The URI for the Intent. (see Intent.setData()).

    action       The action for the Intent (see Intent.setAction()).

    data The data URI for the Intent (see Intent.setData()).

    mimetype         The MIME type for the Intent (see Intent.setType()).

    categories        An iterable data structure containing strings that define categories for the Intent                 (see Intent.addCategory()).

    extras       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.

    component       The component for the Intent (see ComponentName). Using this argument will direct the Intent to a specific class within a specific Android package.

    flags          An iterable data structure containing flags that control how the Intent is handled (see Intent.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.

    一个包含当前屏幕显示的MonkeyImage对象

void touch ( integer x, integer y, string type)

  Sends a touch event specified by type to the screen location specified by x and y.

  发送一个指定类型的touch事件到屏幕的(x,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.

        从屏幕上边开始计算的垂直像素

    type   The type of key event to send. The allowed values are DOWN, UP, and DOWN_AND_UP.

          要发送的key事件类型.允许的值是,DOWN, UP 和 DOWN_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 calling press() for each keycode in message using the key event type DOWN_AND_UP.

    给设备发送包含字母的信息,就像他们是再设备键盘上输入的. 这个等于调用press(keycode,DOWN_AND_UP)函数.

  Arguments

    message  A string containing the characters to send.

          包含字母的字符串.

void wake ()

   Wakes the screen of this device.

    唤醒设备屏幕.

Appendix


Table 1.Property variable names used with getProperty() and getSystemProperty().

Property Group Property Description Notes
build board Code name for the device's system board See Build
brand The carrier or provider for which the OS is customized.
device The device design name.
fingerprint A unique identifier for the currently-running build.
host  
ID A changelist number or label.
model The end-user-visible name for the device.
product The overall product name.
tags Comma-separated tags that describe the build, such as "unsigned" and "debug".
type The build type, such as "user" or "eng".
user  
CPU_ABI The name of the native code instruction set, in the form CPU type plus ABI convention.
manufacturer The product/hardware manufacturer.
version.incremental The internal code used by the source control system to represent this version of the software.
version.release The user-visible name of this version of the software.
version.sdk The user-visible SDK version associated with this version of the OS.
version.codename The current development codename, or "REL" if this version of the software has been released.
display width The device's display width in pixels. SeeDisplayMetricsfor details.
height The device's display height in pixels.
density The logical density of the display. This is a factor that scales DIP (Density-Independent Pixel) units to the device's resolution. DIP is adjusted so that 1 DIP is equivalent to one pixel on a 160 pixel-per-inch display. For example, on a 160-dpi screen, density = 1.0, while on a 120-dpi screen, density = .75.

The value does not exactly follow the real screen size, but is adjusted to conform to large changes in the display DPI. See density for more details.

am.current package The Android package name of the currently running package. The am.currentkeys return information about the currently-running Activity.
action The current activity's action. This has the same format as the name attribute of the action element in a package manifest.
comp.class The class name of the component that started the current Activity. See comp.package for more details.
comp.package The package name of the component that started the current Activity. A component is specified by a package name and the name of class that the package contains.
data The data (if any) contained in the Intent that started the current Activity.
categories The categories specified by the Intent that started the current Activity.
clock realtime The number of milliseconds since the device rebooted, including deep-sleep time. SeeSystemClock for more information.
uptime The number of milliseconds since the device rebooted,not including deep-sleep time
millis current time since the UNIX epoch, in milliseconds.

转载于:https://www.cnblogs.com/hanxiaocai/p/3755519.html

MonkeyDevice Class相关推荐

  1. 老李推荐: 第3章2节《MonkeyRunner源码剖析》脚本编写示例: MonkeyDevice API使用示例 1...

    老李推荐: 第3章2节<MonkeyRunner源码剖析>脚本编写示例: MonkeyDevice API使用示例 上一节我们学习了如何通过MonkeyRunner这个类的静态方法wait ...

  2. 第3章2节《MonkeyRunner源码剖析》脚本编写示例: MonkeyDevice API使用示例(原创)

    天地会珠海分舵注:本来这一系列是准备出一本书的,详情请见早前博文"寻求合作伙伴编写<深入理解 MonkeyRunner>书籍".但因为诸多原因,没有如愿.所以这里把草稿 ...

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

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

  4. MonkeyRunner_MonkeyRunner,MonkeyDevice,MonkeyImage可以调用的方法

    import 由于经常找MonkeyRunner,MonkeyDevice,MonkeyImage可以调用的方法,感觉搜索起来比较麻烦,所以在这总结一下: from com.android.monke ...

  5. MonkeyRunner、MonkeyDevice、MonkeyImage的一些知识

    一.MonkeyRunner:Android SDK中自带的一个黑盒测试工具在PC端通过Android API控制设备的运行 支持Python脚本,可以实现Monkey无法实现的一些逻辑控制 包含:M ...

  6. 自动 Android* 应用测试

    文章转自:http://software.intel.com/zh-cn/articles/automated-android-application-testing/?utm_campaign=CS ...

  7. MonkeyRunner实例及使用说明

    文章转自: http://www.ishow.me/2013/02/06/1035/.html 了解了MonkeyRunner,现在上一个简单的实例(理论支持所有Android设备^_^),向左滑动屏 ...

  8. MonkeyRunner的使用二

    MonkeyRunner可以用来做自动化测试,在Android中做动态分析的时候也可以使用它来做行为触发. 不过感觉使用MonkeyRunner来做行为触发还是很局限的.就比如我想实现外界向模拟器拨打 ...

  9. MonkeyRunner 的使用一

    MonkeyRunner的使用 如果您的英语不错那您可以自己看官网的介绍,如果您需要翻译,其实网上有很多很好的翻译,但是为了学习的完整性,自己还是做了一些重复性的劳动. http://develope ...

  10. 第14章4节《MonkeyRunner源码剖析》 HierarchyViewer实现原理-装备ViewServer-端口转发 3...

    这个处理端口转发的方法主要分3步走: 第1步:获得本地ViewServer转发端口号 第2步:通过Device类发送adb命令创建本地到ViewServer端口转发 第3步:把本地端口号和对应的设备序 ...

最新文章

  1. 区块链教程Fabric1.0源代码分析Tx(Transaction 交易)二
  2. 数字图像缩放之最近邻插值与双线性插值处理效果对比
  3. Linux 中如何复制和删除文件夹中的所有文件?
  4. c++ fork 进程时 共享内存_因为没答好进程间通信,面试挂了...
  5. 【论文解读】GCN论文总结
  6. 小米盒子老是服务器无响应,教你解决小米盒子黑屏死机等故障解决办法!
  7. 前向验证对于模型的更新作用
  8. 【Luogu1393】动态逆序对(CDQ分治)
  9. matlab话pca的双标图biplot,r – 用ggplot2绘制pca biplot
  10. 网页嵌入pdf、在线预览pdf工具及插件(转)
  11. 超3千万人次观看 李佳琦助力中国青年年货节
  12. android 9.0的模拟器,Exagear模拟器最新版
  13. 恩智浦电磁组智能汽车竞赛视频
  14. ESP8285调试记录
  15. 抖音视频什么时候投放dou+最好,dou+投放实战总结:国仁网络资讯
  16. HBase MapReduce MultiTableInput首次测试
  17. C++ primer 个人学习总结
  18. 川土微电子 | CA-IF1051 CAN-FD收发器
  19. oracle用户数据库导错,root 用户操作 ORACLE 数据库导致悲剧
  20. 机器学习(Machine Learning)基础

热门文章

  1. 【干货】《深度学习:Deep Learning》课程PPT下载
  2. 不如跳舞!伯克利的舞蹈动作迁移效果逆天
  3. NLP学习—15.多模态研究方向及在文本分类、文本生成的应用
  4. NLP基础—2.文本预处理
  5. torch.nn.embeding
  6. 最优化方法:深度学习最优化方法
  7. linux普通用户修改root密码及获取root权限
  8. keras可视化模型训练过程
  9. 必须声明标量变量是什么意思_机器视觉学习之halcon系列---一文带你理解handle变量是什么意思...
  10. 不可识别的字符转义序列_大庆事业单位车牌识别道闸多少钱,感应小区车牌识别道闸系统...