2012-12-16 107 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() 
相关问题