这是 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 个参数:device
和serialno
. 所有其他参数都是可选的。在大多数情况下,这些参数是从 ViewClient.connectToDevice() 获得的:
device, serialno = ViewClient.connectToDeviceOrExit()
device.startActivity(component=component)
time.sleep(3)
vc = ViewClient(device, serialno)
重要提示:
您应该只连接到您的设备一次。你只需要MonkeyRunner.waitForConnection
或AndroidViewClient.connectToDeviceOrExit
不需要两者!