我想扩展monkeyrunner API的MonkeyDevice类.
我的派生类看起来像这样.
我的派生类看起来像这样.
from com.android.monkeyrunner import MonkeyDevice,MonkeyRunner class TestDevice(MonkeyDevice): def __init__(self,serial=None): MonkeyDevice.__init__(self) self = MonkeyRunner.waitForConnection(deviceId=serial) self.serial = serial
当我从另一个模块调用test_dev = TestDevice(serial)时,我收到以下错误:
test_dev = TestDevice(serial) TypeError: _new_impl(): 1st arg can't be coerced to com.android.monkeyrunner.core.IMonkeyDevice
我究竟做错了什么?
提前致谢!
解决方法
看来你不能在没有调用工厂函数waitForConnection的情况下直接初始化MonkeyDevice实例.因此,您需要在__new __()函数中指定self,以便MonkeyDevice在将您的实例称为__init__之前将该实例识别为继承自IMonkeyDevice
例:
class TestDevice(MonkeyDevice): def __new__(self,serial=None): return MonkeyRunner.waitForConnection(deviceId=serial) def __init__(self): MonkeyDevice.__init__(self)