Monkey脚本API简介

一、API简介

LaunchActivity(pkg_name, cl_name):启动应用的Activity。参数:包名和启动的Activity。

Tap(x, y, tapDuration): 模拟一次手指单击事件。参数:x,y为控件坐标,tapDuration为点击的持续时间,此参数可省略。

DispatchPress(keyName): 按键。参数: keycode。 详细的Android Keycode列表: http://blog.csdn.net/feizhixuan46789/article/details/16801429

RotateScreen(rotationDegree, persist): 旋转屏幕。 参数:rotationDegree为旋转角度, e.g. 1代表90度;persist表示旋转之后是否固定,0表示旋转后恢复,非0则表示固定不变。

DispatchFlip(true/false): 打开或者关闭软键盘。

LongPress(): 长按2秒。

PressAndHold(x, y, pressDuration): 模拟长按事件。

DispatchString(input): 输入字符串。

Drag(xStart, yStart, xEnd, yEnd, stepCount): 用于模拟一个拖拽操作。

PinchZoom(x1Start, y1Start, x1End, y1End, x2Start, y2Start, x2End, y2End, stepCount): 模拟缩放手势。

UserWait(sleepTime): 休眠一段时间

DeviceWakeUp(): 唤醒屏幕。

PowerLog(power_log_type, test_case_status): 模拟电池电量信息。

WriteLog(): 将电池信息写入sd卡。

RunCmd(cmd): 运行shell命令。

DispatchPointer(downtime,eventTime,action,x,yxpressure,size,metastate,xPrecision,yPrecision,device,edgeFlags): 向指定位置,发送单个手势。

DispatchPointer(downtime,eventTime,action,x,yxpressure,size,metastate,xPrecision,yPrecision,device,edgeFilags): 发送按键消息。

LaunchInstrumentation(test_name,runner_name): 运行一个instrumentation测试用例。

DispatchTrackball: 模拟发送轨迹球事件。

ProfileWait: 等待5秒。

StartCaptureFramerate():  获取帧率。

EndCaptureFramerate(input): 结束获取帧率。

 

二、编写monkey脚本

1. 编写脚本,将此脚本保存为monkey.txt,如下:

 1 #头文件信息
 2 type=raw events
 3 count=10
 4 speed=1.0
 5 start data >>
 6 
 7 #具体的脚本内容
 8 LaunchActivity(com.example.package,com.example.ui.SplashActivity)
 9 Tap(972,1818)
10 UserWait(2000)
11 Tap(540,607)
12 DispatchFlip(false)
13 DispatchString(1234567)
14 Tap(636,859)
15 UserWait(2000)
16 Tap(388,895)
17 UserWait(1000)
18 DispatchString(123456)
19 DispatchFlip(false)
20 UserWait(2000)
21 Tap(540,1104)

2. 执行脚本

1 adb push monkey.txt /sdcard/
2 adb shell monkey -f /sdcard/monkey.txt -v 1
posted @ 2017-11-28 18:11  #天羽Owl  阅读(3050)  评论(2编辑  收藏  举报