我正在尝试使用ADB设置一个自动触摸序列用于测试目的,我已经搜索了几周关于如何创建暂停,长触摸等没有运气的信息。 我知道使用以下方法进行点击和滑动:
input [touchscreen|touchpad] tap <x> <y>
input [touchscreen|touchpad] swipe <x1> <y1> <x2> <y2>
但是我不确定是否可以修改它们来创建我之前提到的东西(暂停,长触摸,保持)。
创建序列的通用脚本会是什么样的:
点按,点按,点按,点按,暂停,长按,暂停,长按,暂停,点按,点按,点按,点按,暂停,重复
出于示例目的,假设所有命令都发生在相同的<x> <y>
位置。
非常感谢任何帮助。
答案 0 :(得分:2)
您可以使用Android SDK附带的工具monkeyrunner来完成此操作。
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyView
device = MonkeyRunner.waitForConnection(timeout = 60, deviceId = "DEVICE_ID")
# DEVICE_ID is the device's serial number obtained by running adb devices
# to tap 4 times
for i in range(4):
device.touch(x, y,MonkeyDevice.DOWN_AND_UP)
# to pause
MonkeyRunner.sleep(no_of_seconds)
# to long touch
device.touch(x, y,MonkeyDevice.DOWN)
MonkeyRunner.sleep(no_of_seconds)
# to release the hold
device.touch(x, y,MonkeyDevice.UP)
现在,要将所有这些包含在重复的cicle中,您可以使用python while或for语句。
monkeyrunner
位于Android-sdk/tools/monkeyrunner
接下来运行./monkeyrunner
,您将进入Jython 2.5.3
或按monkeyrunner ../Desktop/level.py