diff --git a/README.md b/README.md index 6d85acf..a76742e 100644 --- a/README.md +++ b/README.md @@ -752,6 +752,11 @@ Note: click, swipe, drag operations support percentage position values. Example: ```python # get the UI hierarchy dump content xml = d.dump_hierarchy() + + # compressed=True: include not import nodes + # pretty: format xml + # max_depth: limit xml depth, default 50 + xml = d.dump_hierarchy(compressed=False, pretty=False, max_depth=50) ``` * Open notification or quick settings diff --git a/uiautomator2/__init__.py b/uiautomator2/__init__.py index 3c89ef5..f62f370 100644 --- a/uiautomator2/__init__.py +++ b/uiautomator2/__init__.py @@ -262,19 +262,20 @@ def screenshot(self, filename: Optional[str] = None, format="pillow"): elif format == 'raw': return pil_img.tobytes() - def dump_hierarchy(self, compressed=False, pretty=False) -> str: + def dump_hierarchy(self, compressed=False, pretty=False, max_depth: int = None) -> str: """ Dump window hierarchy Args: compressed (bool): return compressed xml pretty (bool): pretty print xml + max_depth (int): max depth of hierarchy Returns: xml content """ try: - content = self._do_dump_hierarchy(compressed) + content = self._do_dump_hierarchy(compressed, max_depth) except HierarchyEmptyError: logger.warning("dump empty, return empty xml") content = '\r\n' @@ -285,15 +286,17 @@ def dump_hierarchy(self, compressed=False, pretty=False) -> str: return content @retry(HierarchyEmptyError, tries=3, delay=1) - def _do_dump_hierarchy(self, compressed=False) -> str: - content = self.jsonrpc.dumpWindowHierarchy(compressed, None) + def _do_dump_hierarchy(self, compressed=False, max_depth=None) -> str: + if max_depth is None: + max_depth = 50 + content = self.jsonrpc.dumpWindowHierarchy(compressed, max_depth) if content == "": raise HierarchyEmptyError("dump hierarchy is empty") # '\r\n' if '' in content: logger.debug("dump empty, call clear_traversed_text and retry") - self.clear_traversed_text() + # self.clear_traversed_text() raise HierarchyEmptyError("dump hierarchy is empty with no children") return content diff --git a/uiautomator2/assets/sync.sh b/uiautomator2/assets/sync.sh index 29f4454..80fc842 100755 --- a/uiautomator2/assets/sync.sh +++ b/uiautomator2/assets/sync.sh @@ -3,7 +3,7 @@ set -e -APK_VERSION="2.3.10" +APK_VERSION="2.3.11" # AGENT_VERSION="0.10.1" cd "$(dirname $0)"