Monkeyrunner. Connect to multiple devices at the same time

天大地大妈咪最大 提交于 2020-01-06 05:14:28

问题


I used this script to connect to multiple Android devices at the same time (i.e. to send files via adb):

from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
import time
import sys
import time
import os

devices = os.popen('adb devices').read().strip().split('\n')[1:]
device1 = MonkeyRunner.waitForConnection( devices[0].split('\t')[0])  
package = 'com.android.browser'
activity = 'com.android.browser.BrowserActivity'
runComponent = package + '/' + activity
device1.startActivity(component=runComponent)

MonkeyRunner.sleep(1)
device2 = MonkeyRunner.waitForConnection( devices[1].split('\t')[0])  
package = 'com.android.browser'

activity = 'com.android.browser.BrowserActivity'
runComponent = package + '/' + activity
device2.startActivity(component=runComponent)

I used

adb 1.0.36 (Rev 1:7.0.0+r33-2) and
monkyrunner(Jython 2.5.3 (2.5:c56500f08d34+, Aug 13 2012, 14:54:35) 

But all I get is:

09:02:54 E/DeviceMonitor: Adb connection Error:EOF                                                                                                                                                                               
09:02:54 E/DeviceMonitor: Connection attempts: 1                                                                                                                                                                                 
09:02:55 E/DeviceMonitor: Connection attempts: 2                                                                                                                                                                                 
09:02:56 E/DeviceMonitor: Connection attempts: 3  

Any hints what to do?

Thanks!

(Original Thread: How to run Monkeyrunner script on multiple devices at the same time )


回答1:


You can use AndroidViewClient/culebra which supports multiple devices. If I recall correctly, this was one of the limitations of monkeyrunner that AndroidViewClient solved.

You can simply generate the script using

$ culebra -Uu --multi-device --start-activity='com.android.chrome/com.google.android.apps.chrome.Main' -o multi-browser.py

which generates a unit test (-U), does not verify what's in the screen dump (-u), use multiple devices, starts a specific activity as a precondition and saves the generated script to multi-device.py.

Then, run the script as

$ multi-browser.py -s all

where -s specifies the serial numbers of the devices where you want the script to run, all in this case, and the browser will start on all of them.



来源:https://stackoverflow.com/questions/51253369/monkeyrunner-connect-to-multiple-devices-at-the-same-time

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!