YBsisterchang 2012-02-02
请大家用下面的范例来做Monkeytest.时间延迟设为300毫秒,基本上符合实际上的触摸间隔。各位只需要改变标记为黄色的部分。
adbshellmonkey-pcom.xxxx.news-s12345--pct-trackball0--pct-nav0--throttle300--pct-anyevent4--ignore-crashes30000&
adbshellmonkey-pcom.xxxx.systeminfo-s12345--pct-trackball0--pct-nav0--throttle300--pct-anyevent4--ignore-crashes30000&
adbshellmonkey-pcom.xxxx.todo-s12345--pct-trackball0--pct-nav0--throttle300--pct-anyevent4--ignore-crashes30000
具体参数查看
http://developer.android.com/guide/developing/tools/monkey.html
一个简单的monkey脚本:
#monkey
tap100180
type123
tap100280
pressDEL
pressDEL
pressDEL
pressDEL
pressDEL
pressDEL
pressDEL
pressDEL
type-460.3
调用monkey脚本
$adbshellamstart-ncom.example.aatg.tc/.TemperatureConverterActivity
Thisisinformedinthelogbythisline:
Starting:Intent{cmp=com.example.aatg.tc/.TemperatureConverterActivity}
Oncetheapplicationhasstartedyoucansendtheeventsusingthescriptandthe
netcatutility:
$nclocalhost1080<monkey.txt
一个monkeyRunner的脚本:monkey_playback.py
#!/usr/bin/envmonkeyrunner
'''
Createdon2011-03-12
@author:diego
'''
importsys
#Importsthemonkeyrunnermodulesusedbythisprogram
fromcom.android.monkeyrunnerimportMonkeyRunner,MonkeyDevice,
MonkeyImage
#Connectstothecurrentdevice,returningaMonkeyDeviceobject
device=MonkeyRunner.waitForConnection()
ifnotdevice:
print>>sys.stderr,"Couldn'tgetconnection"
sys.exit(1)
device.startActivity(component='com.example.aatg.tc/.
TemperatureConverterActivity')
MonkeyRunner.sleep(3.0)
device.type("123")
#Takesascreenshot
MonkeyRunner.sleep(3.0)
result=device.takeSnapshot()
#Writesthescreenshottoafile
result.writeToFile('/tmp/device.png','png')
device.press('KEYCODE_BACK','DOWN_AND_UP')
更详细的文章
http://www.cnblogs.com/yyangblog/archive/2011/03/10/1980086.html