android - 无法在多设备上同时运行 Monkeyrunner 脚本(例如两个 Monkeyrunner 进程)

标签 android monkeyrunner

test.py脚本内容:

import ....

device = MonkeyRunner.waitForConnection(10,sys.argv[1])

device.startActivity(component='package/activity')

'''
some monkeyrunner events
'''

我有两个设备,标记为 device1-id 和 device2-id

  1. 运行monkeyrunner test.py device1-id &

  2. 运行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/

相关文章:

android - 在 Google Maps API v2 中收听“我的位置”图标点击事件

java - 为什么不调用所选上下文项上的函数

具有 3 个 fragment 的 Android 工具栏

android - Monkey Runner 导入出错

android monkey runner 脚本

android - MonkeyRunner 无法使用 startActivity

android - 如何在AsyncTask android中处理HttpResponse

android - 运行一次 kotlin 流,但在下游接收两次

monkeyrunner - Android SDK MonkeyRunner 25.3.2 无法运行

android - 使用 monkeyrunner : How can I call intents during the execution of an application?