008、【uiautomator2, vivo手机报错,求解】获取手机屏幕尺寸时报错,华为手机不报错。

 

device.window_size()  获取手机屏幕尺寸时 vivo手机 报错,华为手机不报错。 求指导原因??

 

代码如下:

from time import sleep

import uiautomator2 as ui2

# 连接手机,a0d5767为被测手机序列号,用adb devices得到
device = ui2.connect("a0d5767")
# device = ui2.connect("79UNW19218002113")


# 1、打印被测设备的信息,打印更多信息(udid、电池等等)
print(device.device_info)

# 2、截图,传路径+文件名
device.screenshot(r"C:\Users\M108112\Desktop\test\test.png")


# 3、打印被测设备的信息,不详细的信息;
print(device.info)

# 4、获取屏幕大小,返回元组类型;
print(device.window_size())

# 3、4方法如果用华为荣耀手机不会报错,用vivo手机报错,报错信息如下:
D:\SkyWorkSpace\WorkSpace\UIAutomator2\day01\venv\Scripts\python.exe D:/SkyWorkSpace/WorkSpace/UIAutomator2/day01/test_03.py
{'udid': 'a0d5767-16:db:d3:bd:15:bc-V2005A', 'version': '10', 'serial': 'a0d5767', 'brand': 'vivo', 'model': 'V2005A', 'hwaddr': '16:db:d3:bd:15:bc', 'sdk': 29, 'agentVersion': '0.10.0', 'display': {'width': 1080, 'height': 2376}, 'battery': {'acPowered': False, 'usbPowered': True, 'wirelessPowered': False, 'status': 5, 'health': 2, 'present': True, 'level': 100, 'scale': 100, 'voltage': 4402, 'temperature': 309, 'technology': 'Li-poly'}, 'memory': {'total': 7627756, 'around': '7 GB'}, 'cpu': {'cores': 8, 'hardware': 'Qualcomm Technologies, Inc SM7250'}, 'arch': '', 'owner': None, 'presenceChangedAt': '0001-01-01T00:00:00Z', 'usingBeganAt': '0001-01-01T00:00:00Z', 'product': None, 'provider': None}
[D 211130 20:01:37 __init__:661] [pid:3868] [a0d5767] kill process(ps): uiautomator
[D 211130 20:01:38 __init__:682] [pid:3868] [a0d5767] uiautomator-v2 is starting ... left: 40.0s
[D 211130 20:01:39 __init__:682] [pid:3868] [a0d5767] uiautomator-v2 is starting ... left: 39.0s
[D 211130 20:01:40 __init__:682] [pid:3868] [a0d5767] uiautomator-v2 is starting ... left: 37.9s
[I 211130 20:01:43 __init__:626] [pid:3868] [a0d5767] restart-uiautomator since "({'code': -32001, 'message': 'java.lang.IllegalStateException', 'data': 'java.lang.IllegalStateException: UiAutomation not connected!\n\tat android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:1198)\n\tat android.app.UiAutomation.waitForIdle(UiAutomation.java:769)\n\tat android.support.test.uiautomator.QueryController.waitForIdle(QueryController.java:532)\n\tat android.support.test.uiautomator.QueryController.waitForIdle(QueryController.java:523)\n\tat android.support.test.uiautomator.QueryController.getCurrentPackageName(QueryController.java:511)\n\tat android.support.test.uiautomator.UiDevice.getCurrentPackageName(UiDevice.java:653)\n\tat com.github.uiautomator.stub.DeviceInfo.<init>(DeviceInfo.java:51)\n\tat com.github.uiautomator.stub.DeviceInfo.getDeviceInfo(DeviceInfo.java:44)\n\tat com.github.uiautomator.stub.AutomatorServiceImpl.deviceInfo(AutomatorServiceImpl.java:161)\n\tat java.lang.reflect.Method.invoke(Native Method)\n\tat com.googlecode.jsonrpc4j.JsonRpcBasicServer.invoke(JsonRpcBasicServer.java:467)\n\tat com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleObject(JsonRpcBasicServer.java:352)\n\tat com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleJsonNodeRequest(JsonRpcBasicServer.java:283)\n\tat com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleRequest(JsonRpcBasicServer.java:251)\n\tat com.github.uiautomator.stub.AutomatorHttpServer.serve(AutomatorHttpServer.java:100)\n\tat fi.iki.elonen.NanoHTTPD.serve(NanoHTTPD.java:2244)\n\tat fi.iki.elonen.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:945)\n\tat fi.iki.elonen.NanoHTTPD$ClientHandler.run(NanoHTTPD.java:192)\n\tat java.lang.Thread.run(Thread.java:919)\n'}, 'deviceInfo')"
[D 211130 20:01:43 __init__:661] [pid:3868] [a0d5767] kill process(ps): uiautomator
[D 211130 20:01:44 __init__:738] [pid:3868] [a0d5767] grant permissions
[D 211130 20:01:45 __init__:682] [pid:3868] [a0d5767] uiautomator-v2 is starting ... left: 40.0s
[D 211130 20:01:46 __init__:682] [pid:3868] [a0d5767] uiautomator-v2 is starting ... left: 39.0s
[D 211130 20:01:47 __init__:682] [pid:3868] [a0d5767] uiautomator-v2 is starting ... left: 37.9s
Traceback (most recent call last):
  File "D:\SkyWorkSpace\WorkSpace\UIAutomator2\day01\venv\lib\site-packages\uiautomator2\__init__.py", line 487, in _jsonrpc_retry_call
    return self._jsonrpc_call(*args, **kwargs)
  File "D:\SkyWorkSpace\WorkSpace\UIAutomator2\day01\venv\lib\site-packages\uiautomator2\__init__.py", line 556, in _jsonrpc_call
    raise err
uiautomator2.exceptions.UiAutomationNotConnectedError: ({'code': -32001, 'message': 'java.lang.IllegalStateException', 'data': 'java.lang.IllegalStateException: UiAutomation not connected!\n\tat android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:1198)\n\tat android.app.UiAutomation.waitForIdle(UiAutomation.java:769)\n\tat android.support.test.uiautomator.QueryController.waitForIdle(QueryController.java:532)\n\tat android.support.test.uiautomator.QueryController.waitForIdle(QueryController.java:523)\n\tat android.support.test.uiautomator.QueryController.getCurrentPackageName(QueryController.java:511)\n\tat android.support.test.uiautomator.UiDevice.getCurrentPackageName(UiDevice.java:653)\n\tat com.github.uiautomator.stub.DeviceInfo.<init>(DeviceInfo.java:51)\n\tat com.github.uiautomator.stub.DeviceInfo.getDeviceInfo(DeviceInfo.java:44)\n\tat com.github.uiautomator.stub.AutomatorServiceImpl.deviceInfo(AutomatorServiceImpl.java:161)\n\tat java.lang.reflect.Method.invoke(Native Method)\n\tat com.googlecode.jsonrpc4j.JsonRpcBasicServer.invoke(JsonRpcBasicServer.java:467)\n\tat com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleObject(JsonRpcBasicServer.java:352)\n\tat com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleJsonNodeRequest(JsonRpcBasicServer.java:283)\n\tat com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleRequest(JsonRpcBasicServer.java:251)\n\tat com.github.uiautomator.stub.AutomatorHttpServer.serve(AutomatorHttpServer.java:100)\n\tat fi.iki.elonen.NanoHTTPD.serve(NanoHTTPD.java:2244)\n\tat fi.iki.elonen.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:945)\n\tat fi.iki.elonen.NanoHTTPD$ClientHandler.run(NanoHTTPD.java:192)\n\tat java.lang.Thread.run(Thread.java:919)\n'}, 'deviceInfo')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\SkyWorkSpace\WorkSpace\UIAutomator2\day01\test_03.py", line 18, in <module>
    print(device.info)
  File "D:\SkyWorkSpace\WorkSpace\UIAutomator2\day01\venv\lib\site-packages\uiautomator2\__init__.py", line 449, in info
    return self.jsonrpc.deviceInfo(http_timeout=10)
  File "D:\SkyWorkSpace\WorkSpace\UIAutomator2\day01\venv\lib\site-packages\uiautomator2\__init__.py", line 480, in __call__
    return self.server._jsonrpc_retry_call(self.method, params,
  File "D:\SkyWorkSpace\WorkSpace\UIAutomator2\day01\venv\lib\site-packages\uiautomator2\__init__.py", line 489, in _jsonrpc_retry_call
    self.reset_uiautomator(str(e))  # uiautomator可能出问题了,强制重启一下
  File "D:\SkyWorkSpace\WorkSpace\UIAutomator2\day01\venv\lib\site-packages\uiautomator2\__init__.py", line 651, in reset_uiautomator
    return self.reset_uiautomator(reason=reason,
  File "D:\SkyWorkSpace\WorkSpace\UIAutomator2\day01\venv\lib\site-packages\uiautomator2\__init__.py", line 651, in reset_uiautomator
    return self.reset_uiautomator(reason=reason,
  File "D:\SkyWorkSpace\WorkSpace\UIAutomator2\day01\venv\lib\site-packages\uiautomator2\__init__.py", line 618, in reset_uiautomator
    raise EnvironmentError(
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] ({'code': -32001, 'message': 'java.lang.IllegalStateException', 'data': 'java.lang.IllegalStateException: UiAutomation not connected!\n\tat android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:1198)\n\tat android.app.UiAutomation.waitForIdle(UiAutomation.java:769)\n\tat android.support.test.uiautomator.QueryController.waitForIdle(QueryController.java:532)\n\tat android.support.test.uiautomator.QueryController.waitForIdle(QueryController.java:523)\n\tat android.support.test.uiautomator.QueryController.getCurrentPackageName(QueryController.java:511)\n\tat android.support.test.uiautomator.UiDevice.getCurrentPackageName(UiDevice.java:653)\n\tat com.github.uiautomator.stub.DeviceInfo.<init>(DeviceInfo.java:51)\n\tat com.github.uiautomator.stub.DeviceInfo.getDeviceInfo(DeviceInfo.java:44)\n\tat com.github.uiautomator.stub.AutomatorServiceImpl.deviceInfo(AutomatorServiceImpl.java:161)\n\tat java.lang.reflect.Method.invoke(Native Method)\n\tat com.googlecode.jsonrpc4j.JsonRpcBasicServer.invoke(JsonRpcBasicServer.java:467)\n\tat com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleObject(JsonRpcBasicServer.java:352)\n\tat com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleJsonNodeRequest(JsonRpcBasicServer.java:283)\n\tat com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleRequest(JsonRpcBasicServer.java:251)\n\tat com.github.uiautomator.stub.AutomatorHttpServer.serve(AutomatorHttpServer.java:100)\n\tat fi.iki.elonen.NanoHTTPD.serve(NanoHTTPD.java:2244)\n\tat fi.iki.elonen.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:945)\n\tat fi.iki.elonen.NanoHTTPD$ClientHandler.run(NanoHTTPD.java:192)\n\tat java.lang.Thread.run(Thread.java:919)\n'}, 'deviceInfo'): 'https://github.com/openatx/uiautomator2/wiki/Common-issues'

Process finished with exit code 1

 

华为荣耀手机执行情况如下:

D:\SkyWorkSpace\WorkSpace\UIAutomator2\day01\venv\Scripts\python.exe D:/SkyWorkSpace/WorkSpace/UIAutomator2/day01/test_03.py
{'udid': '79UNW19218002113-dc:90:88:02:43:02-HRY-AL00a', 'version': '10', 'serial': '79UNW19218002113', 'brand': 'HONOR', 'model': 'HRY-AL00a', 'hwaddr': 'dc:90:88:02:43:02', 'sdk': 29, 'agentVersion': '0.10.0', 'display': {'width': 1080, 'height': 2340}, 'battery': {'acPowered': False, 'usbPowered': False, 'wirelessPowered': False, 'status': 3, 'health': 2, 'present': True, 'level': 32, 'scale': 100, 'voltage': 3725, 'temperature': 340, 'technology': 'Li-poly'}, 'memory': {'total': 3768024, 'around': '4 GB'}, 'cpu': {'cores': 8, 'hardware': 'Hisilicon Kirin710'}, 'arch': '', 'owner': None, 'presenceChangedAt': '0001-01-01T00:00:00Z', 'usingBeganAt': '0001-01-01T00:00:00Z', 'product': None, 'provider': None}
{'currentPackageName': 'com.huawei.android.launcher', 'displayHeight': 2139, 'displayRotation': 0, 'displaySizeDpX': 360, 'displaySizeDpY': 780, 'displayWidth': 1080, 'productName': 'HRY-AL00a', 'screenOn': True, 'sdkInt': 29, 'naturalOrientation': True}
(1080, 2340)

Process finished with exit code 0

 

posted @ 2021-11-30 20:11  空-山-新-雨  阅读(1469)  评论(2编辑  收藏  举报