MR_Android View Client 问题总结及代码片段

1. 无法获取当前视图

06:32:22 E/hierarchyviewer: Unable to get view server version from device emulator-5554

06:32:22 E/hierarchyviewer: Unable to get view server protocol version from device emulator-5554

出现此问题是因为模拟器的调试模式没有打开,调试模式打开后就没有问题了


2. ImportError: No module named dtmilano: 需要把 android view client 的 src添加到path路径中

from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
sys.path.append('/path/to/android_view_client_home/src')
from com.dtmilano.android.viewclient import ViewClient

However, it will work if you just switch the order:

sys.path.append('/path/to/android_view_client_home/src')
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
from com.dtmilano.android.viewclient import ViewClient
3. 
device, serialno = ViewClient.connectToDeviceOrExit(serialno=devices[input])
print("Modifying settings...")
    device.startActivity(settings_uri) 
    vc = ViewClient(device, serialno)

    # Disable screen lock
    vc.findViewWithTextOrRaise("Security").getParent().getParent().touch()
    MonkeyRunner.sleep(3)
    vc.findViewWithTextOrRaise(re.compile('Screen lock')).touch()


你可能感兴趣的:(MonkeyRunner)