How to run Monkeyrunner script on multiple devices at the same time

纵然是瞬间 提交于 2019-12-10 14:47:43

问题


I am trying to run a monkeyrunner script on multiple devices to do some basic operations.I figured out that initialy I will start of writing a script to perform basic action in two connected devices.

  from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice

  import time

   import sys


    import time


   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)

When i run this script, it never finish executing. The browser action happen on one of the connected device but not on other. Can you guys help me fix this or if you have a better code(ideas) to run an activity on multiple devices, Please do let me know~ I am newbie and completely new to the programming world!Thanks in advance


回答1:


you can give like

device1 = MonkeyRunner.waitForConnection('', devices[0].split('\t')[0]) 

this will help




回答2:


A better way to do it is to write a script that explicitly binds to the devices. The link below shows how for emulators

http://chanakaudaya.wordpress.com/2012/04/10/monkeyrunner-tutorial-running-tests-on-multiple-devices-with-monkeyrunner-13/

also seems similar to this question(Which i answered):

Can not simultaneously run monkeyrunner scripts (e.g. two monkeyrunner process) on multi device



来源:https://stackoverflow.com/questions/9652910/how-to-run-monkeyrunner-script-on-multiple-devices-at-the-same-time

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