【问题标题】:Can not simultaneously run monkeyrunner scripts (e.g. two monkeyrunner process) on multi device不能在多台设备上同时运行monkeyrunner脚本(例如两个monkeyrunner进程)
【发布时间】:2012-11-05 12:11:03
【问题描述】:

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

但这不是我需要的。有人知道monkeyrunner为什么会这样吗?

我需要的是,我有一个脚本,可以同时在多台设备上运行相同的脚本。

【问题讨论】:

    标签: android monkeyrunner


    【解决方案1】:

    你必须指定猴子端口,所以你可能想使用这样的命令行参数

     # 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  
    

    【讨论】:

    • 谢谢 rytan,对不起,我说得不清楚。你告诉我在脚本中定义一个 var ,并使脚本可以在运行测试中重复使用。我想知道的是,实际上我同时在两个设备或模拟器上运行了两个相同的 monkeyrunner 脚本,我发现 device2 中的一些关键事件被发送到了 device1-id。不知道为什么?
    • 争论的原因是,monkey runner 是使用 tcp/ip 运行的,没有它我有命令被发送到错误的模拟器。我必须确保它只向指定的“客户端”发送命令。我有一个脚本同时在 3 个模拟器上运行,唯一的变化是它们运行的​​模拟器有不同的端口。
    • 抱歉最近才回复。在我的想法中,我认为,2个设备连接到电脑,那么每个设备(模拟器)应该有两个不同的端口。并且序列号(“adb devices”打印)将指向指定的设备。所以在我的脚本中,我只是将序列号传递给参数。我认为你的sciprt和我的没有什么不同。真的不能在我的脚本中工作,我需要更深入地挖掘。
    • 在我的情况下,设备将具有不同的端口号,我启动了两个不同的模拟器,它们是原始的克隆。例如,Tester5554 和 Tester5556。问题是monkeyrunner 需要知道与哪个模拟器对话。这是一篇展示我关注的 emaple 的文章chanakaudaya.wordpress.com/2012/04/10/…
    • 还请注意,最好尝试多设备作为模拟器,因为设备编号始终是“emultor-”端口
    【解决方案2】:

    我相信 Monkeyrunner 不是线程安全的。

    要对此进行测试,请创建 2 个脚本,将 deviceId 硬编码到每个脚本中。 启动每个脚本: 在 Windows 中,使用“启动脚本 1”,然后使用“启动脚本 2” 在 Unix 中使用 "script1 &; script2 &"

    请注意,script1 在看起来可以正常工作后失败并出现错误。并且 SCript2 也未能按照预期执行,因为它从两个窗口获取命令。

    【讨论】:

    • 我以前从未想过。你有没有关于 monkeyrunner 的非线程安全的资料?谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-02
    • 2018-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-13
    相关资源
    最近更新 更多