2014년 1월 28일 화요일

Make complex touch event on Android using monkeyrunner


You can control Android device simply using monkeyrunner.
But, because it supports only simple DRAG command which just drag from one point to other point in specific speed, users couldn't reproduce real people's complex(e.g., drawing complex picture or remove app icon from home screen) touch event.

So, I modified monkeyrunner to provide MOVE event and contributed the code to AOSP. It merged soon.
(https://android-review.googlesource.com/#/c/50991/)

After that, one day, one guy asked about how the feature can be used on stackoverflow and sent mail about that to me.
(http://stackoverflow.com/questions/18161416/android-monkey-runner-touch-with-move)

So, I made and shared a simple example code for that question. I think it would be better to share it here, too.

#!/usr/bin/env monkeyrunner
import time
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
device = MonkeyRunner.waitForConnection()
# Touch down screen
device.touch(100, 500, MonkeyDevice.DOWN)
# Move from 100, 500 to 300, 500
for i in range(1, 11):
device.touch(100 + 20 * i, 500, MonkeyDevice.MOVE)
print "move ", 100 + 20 * i, 500
time.sleep(0.1)
# Move from (300, 500 to 200, 500)
for i in range(1, 11):
device.touch(300, 500 - 10 * i, MonkeyDevice.MOVE)
print "move ", 300, 500 - 10 * i
time.sleep(0.1)
# Remove finger from screen
device.touch(300, 400, MonkeyDevice.UP)
view raw gistfile1.py hosted with ❤ by GitHub
Just use the type MOVE like DOWN, UP as argument inside touch function call.
Hope it can be helpful to someone ;)

댓글 없음:

댓글 쓰기