uiautomator2连接,python命令行里connect正常,print(d.info)就报错
另外,执行了python -m uiautomator2 init,显示successful,但是手机上找不到atx 和com.github.uiautomator.test
import uiautomator2
>>> d = uiautomator2.connect()
[I 200430 18:38:17 init:155] uiautomator2 version: 2.7.3
[I 200430 18:38:17 init:348] Install minicap, minitouch
[I 200430 18:38:17 init:363] Install com.github.uiautomator, com.github.uiautomator.test 2.3.1
[I 200430 18:38:18 init:328] - app-uiautomator.apk installed
[I 200430 18:38:19 init:328] - app-uiautomator-test.apk installed
[I 200430 18:38:19 init:373] Check atx-agent version
Successfully init AdbDevice(serial=4b285f2c)
>>> print(d.info)
C:\Users\luojie\Anaconda3\lib\site-packages\uiautomator2\__init__.py:558: RuntimeWarning: uiautomator2 is not reponding, restart uiautomator2 automatically
stacklevel=1)
[D 200430 18:38:27 __init__:774] restart-uiautomator since "UiAutomator stopped"
[D 200430 18:38:27 __init__:844] Device: Xiaomi, 4b285f2c
[D 200430 18:38:27 __init__:854] kill process(ps): uiautomator
[D 200430 18:38:28 __init__:868] uiautomator-v2 is starting ... left: 40.0s
[D 200430 18:38:29 __init__:868] uiautomator-v2 is starting ... left: 39.0s
[D 200430 18:38:30 __init__:868] uiautomator-v2 is starting ... left: 37.9s
[D 200430 18:38:30 __init__:774] restart-uiautomator since "UiAutomator stopped"
[D 200430 18:38:30 __init__:844] Device: Xiaomi, 4b285f2c
[D 200430 18:38:30 __init__:854] kill process(ps): uiautomator
[D 200430 18:38:30 __init__:826] grant permissions
[D 200430 18:38:31 __init__:868] uiautomator-v2 is starting ... left: 40.0s
[D 200430 18:38:32 __init__:868] uiautomator-v2 is starting ... left: 39.0s
[D 200430 18:38:33 __init__:868] uiautomator-v2 is starting ... left: 37.9s
Traceback (most recent call last):
File "<ipython-input-5-663fb1bf5cfd>", line 1, in <module>
print(d.info)
File "C:\Users\luojie\Anaconda3\lib\site-packages\uiautomator2\__init__.py", line 1616, in __getattr__
return getattr(self._default_session, attr)
File "C:\Users\luojie\Anaconda3\lib\site-packages\uiautomator2\session.py", line 601, in info
return self.jsonrpc.deviceInfo()
File "C:\Users\luojie\Anaconda3\lib\site-packages\uiautomator2\__init__.py", line 547, in __call__
http_timeout)
File "C:\Users\luojie\Anaconda3\lib\site-packages\uiautomator2\__init__.py", line 559, in jsonrpc_retry_call
self.reset_uiautomator("UiAutomator stopped")
File "C:\Users\luojie\Anaconda3\lib\site-packages\uiautomator2\__init__.py", line 791, in reset_uiautomator
depth=depth + 1)
File "C:\Users\luojie\Anaconda3\lib\site-packages\uiautomator2\__init__.py", line 791, in reset_uiautomator
depth=depth + 1)
File "C:\Users\luojie\Anaconda3\lib\site-packages\uiautomator2\__init__.py", line 771, in reset_uiautomator
"adb shell am instrument -w -r -e debug false -e class com.github.uiautomator.stub.Stub com.github.uiautomator.test/android.support.test.runner.AndroidJUnitRunner",
OSError: [WinError adb shell am instrument -w -r -e debug false -e class com.github.uiautomator.stub.Stub com.github.uiautomator.test/android.support.test.runner.AndroidJUnitRunner] UiAutomator stopped: 'https://github.com/openatx/uiautomator2/wiki/Common-issues'
直接
python -m weditor
连接手机,发现报错:
Local server not started, start with
python -m weditor
解决方法:小米手机没开usb安装,所以atx和com.github.uiautomator.test都没安装上,在开发者选项中打开 usb安装 ,命令行执行
python -m uiautomator2 init
在手机端点同意安装,再执行
python -m weditor
填入手机序列号即可,但目前仍然不能通过ip连接。