モンキーランナーを使用して、同じPCに接続された複数のタブレットを構成しようとしています。コードは1つのタブレットで問題なく機能しますが、複数のタブレットで実行しようとすると、すべてが失敗します。
これがmonkeyrunnerpythonファイルを呼び出すコードです。mr1.pyは、私が実行しようとしているmonkeyrunnerファイルです。
import sys
import util
import threading
import commands
class myThread (threading.Thread):
def __init__(self, threadID, deviceId,env_path):
self.threadID = threadID
self.deviceId = deviceId
self.path = env_path
threading.Thread.__init__(self)
def run(self):
print "Starting " + self.deviceId
ret = commands.getstatusoutput(self.path+"monkeyrunner mr1.py "+self.deviceId)
print ret
print "Exiting " + self.deviceId
def main():
connected_devices = util.get_connected_devices()
count = 0
path = "/Users/ad/Desktop/android-sdk-macosx/tools/"
for device in connected_devices:
thread = myThread(count,device[0],path)
thread.start()
count = count + 1
if __name__ == "__main__":
main()
モンキーランナーの競合状態について説明しているこのブログ投稿に出くわしました。それが問題の原因かどうかはわかりません。
http://distributedreasoner.blogspot.com/2011/06/android-monkeyrunner-and-google-adb.html
上記のブログ投稿に記載されているMAMLライブラリも使用してみましたが、monkeyrunnerを複数のデバイスでシミュレートして実行させることができませんでした。これが実際のmonkeyrunnerコードです。
import sys
import maml
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
deviceId = sys.argv[1]
# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection(10.0,deviceId)
packagename = "com.android.settings"
classname = "com.android.settings.DisplaySettings" #SecuritySettings" #".DisplaySettings"
componentname = packagename + "/" + classname
device.startActivity(component=componentname)
maml.click(device,1088,300)
MonkeyRunner.sleep(0.4)
maml.click(device,864,361)
MonkeyRunner.sleep(0.4)
maml.click(device,612,621)
MonkeyRunner.sleep(0.5)
device.press ('KEYCODE_HOME', 'DOWN_AND_UP')
print "Exiting for device !" + deviceId
Commonswareの質問に基づいて、スレッデッドコードを次のシーケンシャルコードに置き換えました。問題なく動作しているようですが、これは明らかに最も理想的な状況ではありません。
for device in connected_devices:
print device[0]
ret = commands.getstatusoutput(path+"monkeyrunner mr1.py "+device[0])
print ret
Androidでは場所や言語の設定などをプログラムで変更することはできず、設定を変更するために多くのタブレットを構成する必要があるため、当面のオプションはMonkeyRunnerを使用することでした。いくつかの注意点として、私はこの問題を解決するためにmonkeyrunner以外で使用できる他のツールを受け入れています。この問題についての助けをいただければ幸いです。