使用Android中提供的自动化测试工具Monkeyrunner实现的小例子。
实例一
程序启动之后点击按钮 click.py:
from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImage
device=MonkeyRunner.waitForConnection()
device.press('KEYCODE_DPAD_DOWN','DOWN_AND_UP')
device.press('KEYCODE_DPAD_CENTER','DOWN_AND_UP')
在cygwin环境下,用shell脚本执行click.py:
java -Xmx512m "-Djava.ext.dirs=/cygdrive/c/D/android-sdk-windows/tools/lib;/cygdrive/c/D/android-sdk-windows/tools/lib/x86" -Dcom.android.monkeyrunner.bindir=c:/D/android-sdk-windows/tools/ -jar c:/D/android-sdk-windows/tools/lib/monkeyrunner.jar click.py
实例二
退出程序返回主屏home.py:
from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImage
device=MonkeyRunner.waitForConnection()
device.press('KEYCODE_HOME',MonkeyDevice.DOWN_AND_UP)