您的位置:首页 > 产品设计 > UI/UE

UI自动测试工具monkey

2011-10-25 22:45 232 查看

Monkey脚本

Monkey脚本支持的命令

脚本命令必须为小写字母

脚本命令以回车符作为一条命令的结束

键盘按下/弹起

key [down|up] keycode


这个命令模拟一次键盘输入。

keycode参数值详见KeyEvent类的KEYCODE列表。这个参数的格式很灵活,例如模拟菜单按钮可以使用82(菜单按钮的键值),也可以使用 KEYCODE_MENU(键值的名称,必须严格都是大写字母),还可以使用menu(Monkey程序会自动添加KEYCODE部分,此时并不区分大小 写)。

注意一次完整的敲击(press)操作是一个按下(key down)和弹起(key up)的组合

触摸按下/弹起/移动

touch [down|up|move] x y

This command injects a MotionEvent into the input system that simulates a user touching the touchscreen (or a pointer event). x and y specify coordinates on the display (0 0 being the upper left) for the touch event to happen. Just like key events, touch events at a single location require both a down and an up. To simulate dragging, send a “touch down”, then a series of “touch move” events (to simulate the drag), followed by a “touch up” at the final location.

滚动轨迹球

trackball dx dy

This command injects a MotionEvent into the input system that simulates a user using the trackball. dx and dy indicates the amount of change in the trackball location (as opposed to exact coordinates that the touch events use)

打开/关闭实体键盘

flip [open|close]


模拟一次实体键盘的打开/关闭。

在没有实体键盘的手机上此命令无效。

唤醒设备(点亮屏幕)

wake


这个命令将唤醒设备,并允许用户输入。

如果设备键盘已锁,这个命令并不能解锁键盘

屏幕点击

tap x y


这个命令模拟一次屏幕点击。

这个命令就是touch down和touch up命令的一次组合。

敲击键盘

press keycode


这个命令模拟一次键盘敲击。

这个命令就是key down和key up命令的一次组合。

键入字符串

type string


这个命令模拟键入一个字符串

该命令会完全模拟每一个字符的键盘事件

列出环境变量

listvar


该命令将列出Monkey的所有环境变量。

返回值为空格分隔的字符串。

参考:Nexus S中Monkey的环境变量

am.current.action

am.current.categories

am.current.comp.class

am.current.comp.package

am.current.data

am.current.package

build.board

build.brand

build.cpu_abi

build.device

build.display

build.fingerprint

build.host

build.id

build.manufacturer

build.model

build.product

build.tags

build.type

build.user

build.version.codename

build.version.incremental

build.version.release

build.version.sdk

clock.millis

clock.realtime

clock.uptime

display.density 设备屏幕密度

display.height 设备纵向像素

display.width 设备横向像素

获取环境变量值

getvar varname


该命令用于获取指定的环境变量的值。

通过listvar命令获取支持的环境变量列表。

退出Monkey

quit


完全退出Monkey

Monkey不再接受新的连接。

结束当前会话

done


结束当前会话。

Monkey还可以接受新的连接。

休眠

sleep ms


使Monkey进入休眠一段时间,参数为整数,单位毫秒

注释

#


以#开头的语句会被Monkey当做注释。发送这样的命令Monkey不会返回错误也不会返回OK。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: