我正在使用monkeyrunner测试Android UI。我使用startActivity(组件)使用MonkeyRunner成功启动了一个活动。但现在我想使用以下代码单击名为“Example”的UI上的按钮:
device.startActivity(成分= runComponent)
VC = ViewClient(装置)
vc.dump()
当我运行这个python脚本时,在到达此行时,我的脚本以错误结束
VC = ViewClient(装置)
TypeError:_ init ()至少需要3个参数(2个给定)
我做错了什么?
先谢谢
答案 0 :(得分:2)
可以使用monkey runner
中的以下行按下名称为条目的视图vc=ViewClient.findViewWithText('Entry')
vc.touch()
答案 1 :(得分: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个参数:device
和serialno
。
所有其他参数都是可选的。
在大多数情况下,这些参数是从ViewClient.connectToDevice()获得的:
device, serialno = ViewClient.connectToDeviceOrExit()
device.startActivity(component=component)
time.sleep(3)
vc = ViewClient(device, serialno)
重要:强>
您应该只连接一次设备。您只需要MonkeyRunner.waitForConnection
或AndroidViewClient.connectToDeviceOrExit
而不是 BOTH !