Skip to content

Commit

Permalink
update apk to 2.3.11 to fix dump_hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed May 14, 2024
1 parent 36c333f commit 64c6f2b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions uiautomator2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<?xml version=\'1.0\' encoding=\'UTF-8\' standalone=\'yes\' ?>\r\n<hierarchy rotation="0" />'
Expand All @@ -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")

# '<?xml version=\'1.0\' encoding=\'UTF-8\' standalone=\'yes\' ?>\r\n<hierarchy rotation="0" />'
if '<hierarchy rotation="0" />' 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

Expand Down
2 changes: 1 addition & 1 deletion uiautomator2/assets/sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

set -e

APK_VERSION="2.3.10"
APK_VERSION="2.3.11"
# AGENT_VERSION="0.10.1"

cd "$(dirname $0)"
Expand Down

0 comments on commit 64c6f2b

Please sign in to comment.