Givemepass's Android 惡補筆記

如何使用MonkeyRunner

| Comments

Android提供MonkeyRunner來進行UI Test

Jython 2.5.3 (2.5:c56500f08d34+, Aug 13 2012, 14:54:35)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_40
>>> from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
>>> device = MonkeyRunner.waitForConnection()
>>> for i in range(1,10):
...    device.touch(545,545,MonkeyDevice.DOWN_AND_UP)
...    MonkeyRunner.sleep(0.3)
...
>>>

上面可以看到一開始

>>> from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
>>> device = MonkeyRunner.waitForConnection()

先進行裝置上連結

接著跑for迴圈

>>> for i in range(1,10):
...    device.touch(545,545,MonkeyDevice.DOWN_AND_UP)
...    MonkeyRunner.sleep(0.3)
...
>>>

這樣就會觸控螢幕上某點連點10次

Comments

comments powered by Disqus