1

我正在尝试使用 ADB 设置自动触摸序列以进行测试,我已经搜索了几个星期关于如何创建暂停、长触摸等的信息,但没有运气。我知道将以下内容用于点击和滑动:

input [touchscreen|touchpad] tap <x> <y>
input [touchscreen|touchpad] swipe <x1> <y1> <x2> <y2>

但我不确定是否可以修改它们来创建我之前提到的东西(暂停、长按、保持)。

一般脚本会是什么样子来创建一个序列,例如:

点击,点击,点击,点击,暂停,长按,暂停,长按,暂停,点击,点击,点击,点击,暂停,重复

例如,假设所有命令都发生在相同的<x> <y>位置。

任何帮助深表感谢。

4

1 回答 1

2

您可以使用monkeyrunner(Android SDK 附带的一个工具)来执行此操作。

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

于 2013-06-17T10:15:01.403 回答