test.py脚本内容:
import ....
device = MonkeyRunner.waitForConnection(10,sys.argv[1])
device.startActivity(component='package/activity')
'''
some monkeyrunner events
'''
我有两个设备,标记为 device1-id 和 device2-id
运行monkeyrunner test.py device1-id &
运行monkeyrunner test.py device2-id &
我发现device2-id中的一些事件被发送到device1-id。不知道为什么?
我注意到一些教程,他们说,如果在更多设备上运行monkeyrunner,可以编写如下脚本:
device1 = MonkeyRunner.waitForConnection(10,device1-id)
device2 = MonkeyRunner.waitForConnection(10,device2-id)
device1.actions
device2.actions
但这不是我需要的。有人知道为什么猴子跑者会这样做吗?
我需要的是,我有一个脚本,可以在多个设备上同时运行相同的脚本。
最佳答案
您必须指定猴子端口,因此您可能需要像这样使用命令行参数
# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
import sys
# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection(timeOut,"emulator-"+ sys.argv[1])
MONKEYRunner Actions . . . .
注意:sys.arv[0] 始终是测试文件
通过在命令行中输入以下内容来调用:
monkeyrunner test.py PortNumber
关于android - 无法在多设备上同时运行 Monkeyrunner 脚本(例如两个 Monkeyrunner 进程),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13231856/