【问题标题】:TypeError: _init_() takes at least 3 arguments (2 given) MonkeyRunnerTypeError: _init_() 至少需要 3 个参数(给定 2 个) MonkeyRunner
【发布时间】:2012-12-16 08:56:01
【问题描述】:

我正在使用 monkeyrunner 测试 Android UI。我成功地使用 startActivity(component) 使用 MonkeyRunner 启动了一项活动。但现在我想使用以下代码在我的 UI 上单击一个名为“示例”的按钮:

device.startActivity(component=runComponent)

vc=ViewClient(设备)

vc.dump()

当我运行这个 python 脚本时,当我到达这一行时,我的脚本以错误结束

vc=ViewClient(设备)

TypeError: _init() 至少需要 3 个参数(2 个给定)

我做错了什么?

提前致谢

【问题讨论】:

    标签: android testing monkeyrunner


    【解决方案1】:

    一个名为Entry的视图可以在monkey runner中使用以下行来按下

    vc=ViewClient.findViewWithText('Entry')
    vc.touch()
    

    【讨论】:

      【解决方案2】:

      这是 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)
      

      重要提示: 您应该只连接到您的设备一次。你只需要MonkeyRunner.waitForConnectionAndroidViewClient.connectToDeviceOrExit 而不是BOTH

      【讨论】:

      • 应用上述更改后,我的活动没有启动,命令提示符是静态的,显示 121216 15:33:29.016:I [MainThread] [com.android.chimpchat.ChimpManager] Monkey Command: wake.没有进一步的回应
      • 可能是 Chimpchat 错误。尝试重启 adb:adb kill-server
      猜你喜欢
      • 2017-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-12
      相关资源
      最近更新 更多