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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
Hope it can be helpful to someone ;)
댓글 없음:
댓글 쓰기