Monkey写脚本

今天学习使用monkey测试一个应用的登陆,遇到些问题记录下:

先上代码:

type=raw events
count = 1
speed = 1.0
start data >>
LauncheActivity(com.android.smartmirror,com.android.smartmirror.activities.MainActivity)
UserWait(500)

//用户名输入框
DipatchePointer(0,0,0,271,391,0,0,0,0,0,0,0)
DipatchePointer(0,0,1,271,391,0,0,0,0,0,0,0)
UserWait(1500)
DispatchString(9876543210) //用户名
UserWait(500)

//密码输入框
DipatchePointer(0,0,0,242,595,0,0,0,0,0,0,0)
DipatchePointer(0,0,1,242,595,0,0,0,0,0,0,0)
UserWait(1500)
DispatchString(1234567890)
UserWait(1500)
Tap(620,810,1500)
UserWait(1500)

结果运行的时候,光标在哪,就在哪连续输入9876543210、1234567890,也不换对应的输入框,很郁闷,不是道是什么原因(有哪位大神知道,请指教一下)。后来想了个办法,使用Tap,结果脚本变成下满的样子:

type=raw events
count = 1
speed = 1.0
start data >>
LauncheActivity(com.android.smartmirror,com.android.smartmirror.activities.MainActivity)
UserWait(500)
//用户名输入框
Tap(271,391,500)
UserWait(1500)
DipatchePointer(0,0,0,271,391,0,0,0,0,0,0,0)
DipatchePointer(0,0,1,271,391,0,0,0,0,0,0,0)
UserWait(1500)
DispatchString(9876543210) //用户名
UserWait(500)
//密码输入框
Tap(242,595,500)
UserWait(1500)
DipatchePointer(0,0,0,242,595,0,0,0,0,0,0,0)
DipatchePointer(0,0,1,242,595,0,0,0,0,0,0,0)
UserWait(1500)
DispatchString(1234567890)
UserWait(1500)
Tap(620,810,1500)
UserWait(1500)

运行正常了,但貌似脚本中没必要使用DispatchPointer,就试了一下变成下面的脚本:

type=raw events
count = 1
speed = 1.0
start data >>
LauncheActivity(com.android.smartmirror,com.android.smartmirror.activities.MainActivity)
UserWait(500)
Tap(271,391,500)
UserWait(1500)
DispatchString(9876543210)
UserWait(500)
Tap(242,595,500)
UserWait(1500)
DispatchString(1234567890)
UserWait(1500)
Tap(620,810,1500)
UserWait(1500)

结果运行也是正常的,现在更纳闷了,那DispatchPointer到底什么时候用呢?有哪位大神知道,请解下惑,不胜感激,谢谢。

posted @ 2018-05-12 18:07  田雨二  阅读(134)  评论(0编辑  收藏  举报