2012-12-16 96 views
1

我正在使用monkeyrunner測試Android UI。我成功地使用startActivity(component)使用MonkeyRunner開始了一個活動。但現在我想點擊我的UI中的按鈕和一個名爲「示例」使用下面的代碼:TypeError:_init_()至少需要3個參數(給出2個參數)MonkeyRunner

device.startActivity(component=runComponent)

vc=ViewClient(device)

vc.dump()

當我運行這個python腳本,一旦到達此行我的腳本錯誤結束

vc=ViewClient(device)

TypeError: _init() takes at least 3 arguments (2 Given)

什麼我做錯了嗎?

由於提前

回答

0

這是ViewClient的初始化簽名和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) 

重要: 您應該連接到您的設備只有一次。您只需要MonkeyRunner.waitForConnectionAndroidViewClient.connectToDeviceOrExit而不是BOTH

+0

被壓將上述變更後,我的活性沒有開始和命令提示是靜態表示 121216 15:33:29.016 :我[MainThread] [com.android.chimpchat.ChimpManager]猴子命令:喚醒。 沒有furthur響應 –

+0

可能是一個Chimpchat錯誤。嘗試重新啓動adb:adb kill-server –

2

與名稱條目A視圖可使用下面的行中猴轉輪

vc=ViewClient.findViewWithText('Entry') 
vc.touch() 
相關問題