From 75fe28645dc20fbec8e9073fa9bd8ef1b96f567c Mon Sep 17 00:00:00 2001 From: codeskyblue Date: Fri, 9 Aug 2024 19:20:43 +0800 Subject: [PATCH] add HTTPTimeoutError --- README.md | 2 ++ uiautomator2/core.py | 4 +++- uiautomator2/exceptions.py | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0936f39..29bd551 100644 --- a/README.md +++ b/README.md @@ -1229,6 +1229,8 @@ d.settings['operation_delay'] = (.5, 1) # 其中 double_click, long_click 都对应click d.settings['operation_delay_methods'] = ['click', 'swipe', 'drag', 'press'] d.settings['wait_timeout'] = 20.0 # 默认控件等待时间(原生操作,xpath插件的等待时间) + +d.settings['max_depth'] = 50 # 默认50,限制dump_hierarchy返回的元素层级 ``` 对于随着版本升级,设置过期的配置时,会提示Deprecated,但是不会抛异常。 diff --git a/uiautomator2/core.py b/uiautomator2/core.py index 0feb227..b043c3d 100644 --- a/uiautomator2/core.py +++ b/uiautomator2/core.py @@ -18,7 +18,7 @@ import adbutils import requests -from uiautomator2.exceptions import RPCInvalidError, RPCStackOverflowError, UiAutomationNotConnectedError, HTTPError, LaunchUiAutomationError, UiObjectNotFoundError, RPCUnknownError, APKSignatureError, AccessibilityServiceAlreadyRegisteredError +from uiautomator2.exceptions import HTTPTimeoutError, RPCInvalidError, RPCStackOverflowError, UiAutomationNotConnectedError, HTTPError, LaunchUiAutomationError, UiObjectNotFoundError, RPCUnknownError, APKSignatureError, AccessibilityServiceAlreadyRegisteredError from uiautomator2.abstract import AbstractUiautomatorServer from uiautomator2.utils import is_version_compatiable from uiautomator2.version import __apk_version__ @@ -111,6 +111,8 @@ def _http_request(dev: adbutils.AdbDevice, method: str, path: str, data: Dict[st print(response.text.rstrip()) print(f"<<< END timed_used = %.3f\n" % (end_time - start_time).total_seconds()) return response + except requests.Timeout as e: + raise HTTPTimeoutError(f"HTTP request timeout: {e}") from e except requests.RequestException as e: raise HTTPError(f"HTTP request failed: {e}") from e diff --git a/uiautomator2/exceptions.py b/uiautomator2/exceptions.py index 9b37c26..0182efb 100644 --- a/uiautomator2/exceptions.py +++ b/uiautomator2/exceptions.py @@ -33,6 +33,7 @@ class DeviceError(BaseException): ... class AdbShellError(DeviceError):... class ConnectError(DeviceError):... class HTTPError(DeviceError):... +class HTTPTimeoutError(HTTPError):... class AdbBroadcastError(DeviceError):... class UiAutomationError(DeviceError):...