0

モンキーランナーを使用して、同じ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以外で使用できる他のツールを受け入れています。この問題についての助けをいただければ幸いです。

4

1 に答える 1

1

どの設定を変更しようとしていますか?言語が唯一の場合は、アプリケーション内で言語を実行できます。

public void setLocale(Locale locale, Instrumentation inst){
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    inst.getTargetContext().getResources().updateConfiguration(config, inst.getTargetContext().getResources().getDisplayMetrics());
}

すべてのタブレットはAPIレベル16以上(jely bean?)ですか?そうであれば、http: //developer.android.com/tools/testing/testing_ui.htmlを参照してください。

最後に、それでもモンキーランナーでそれを実行したい場合は、すべてのデバイスを1つのスレッドで取得してから、各デバイスを各スレッドに個別に渡すことをお勧めします。

Pythonは私の専門ではなく、使用しているすべてのライブラリへのアクセス/知識がありません(Javaで実行できますか?)が、うまくいくと思うのは次のようなものです。

class myThread (threading.Thread):
    def __init__(self, device):
        self.device = device
        threading.Thread.__init__(self)

    def run(self):
        packagename = "com.android.settings"
        classname = "com.android.settings.DisplaySettings"
        componentname = packagename + "/" + classname
        self.device.startActivity(component=componentname)
        maml.click(self.device, 1088, 300)
        MonkeyRunner.sleep(0.4)
        maml.click(self.device, 864, 361)
        MonkeyRunner.sleep(0.4)
        maml.click(self.device, 612, 621)
        MonkeyRunner.sleep(0.5)
        self.device.press('KEYCODE_HOME', 'DOWN_AND_UP')


def main():
    connected_devices = util.get_connected_devices()
    count = 0
    devices = []
    for deviceId in connected_devices:
        devices[count] = MonkeyRunner.waitForConnection(10.0, deviceId[0])
        count = count + 1
    for device in devices:
        thread = myThread(device)
        thread.start()


if __name__ == "__main__":
    main()

基本的に違いは、上記のように、すべてのデバイスを順番に取得してから、取得したデバイスで各スレッドを順番に呼び出すことです。それは理にかなっていますか?

于 2012-11-19T21:36:36.277 に答える