1

monkeyrunner を使用して Android UI をテストしています。startActivity(component) を使用して MonkeyRunner を使用してアクティビティを開始することに成功しました。しかし、次のコードを使用して、「Example」という名前の UI のボタンをクリックしたいと思います。

device.startActivity(コンポーネント=runComponent)

vc=ViewClient(デバイス)

vc.dump()

このpythonスクリプトを実行すると、この行に到達するとスクリプトがエラーで終了します

vc=ViewClient(デバイス)

TypeError: _ init () は少なくとも 3 つの引数を取ります (2 つ指定)

私は何を間違っていますか?

前もって感謝します

4

2 に答える 2

2

名前がEntryのビューは、monkey runner で次の行を使用して押すことができます

vc=ViewClient.findViewWithText('Entry')
vc.touch()
于 2012-12-19T19:05:05.337 に答える
0

これは、ViewClient のinit署名と epydoc です。

def __init__(self, device, serialno, adb=None, autodump=True, localport=VIEW_SERVER_PORT, remoteport=VIEW_SERVER_PORT, startviewserver=True):
    '''
    Constructor

    @type device: MonkeyDevice
    @param device: The device running the C{View server} to which this client will connect
    @type serialno: str
    @param serialno: the serial number of the device or emulator to connect to
    @type adb: str
    @param adb: the path of the C{adb} executable or None and C{ViewClient} will try to find it
    @type autodump: boolean
    @param autodump: whether an automatic dump is performed at the end of this constructor
    @type localport: int
    @param localport: the local port used in the redirection
    @type remoteport: int
    @param remoteport: the remote port used to start the C{ViewServer} in the device or
                       emulator
    @type startviewserverparam: boolean
    @param startviewserverparam: Whether to start the B{global} ViewServer
    '''

ご覧のとおり、initは少なくとも 2 つの引数を取ります:deviceserialno. 他のすべての引数はオプションです。ほとんどの場合、これらの引数は ViewClient.connectToDevice() から取得されます。

device, serialno = ViewClient.connectToDeviceOrExit()
device.startActivity(component=component)
time.sleep(3)
vc = ViewClient(device, serialno)

重要: デバイスへの接続は 1 回だけにしてください。両方が必要なMonkeyRunner.waitForConnection場合とそうでAndroidViewClient.connectToDeviceOrExitない場合があります。

于 2012-12-16T09:52:41.923 に答える