Skip to content

Fix negative bounds, off-screen filtering, and multiline labels in Android screen.py - #28

Merged
pierridotite merged 1 commit into
pierridotite:mainfrom
brixtonpham:fix/android-negative-bounds
Nov 26, 2026
Merged

pierridotite merged 1 commit into
pierridotite:mainfrom
brixtonpham:fix/android-negative-bounds

Conversation

@brixtonpham

Copy link
Copy Markdown
Contributor

Problem

scripts/android/screen.py currently parses UIAutomator bounds with re.findall(r"\d+", ...) instead of r"-?\d+" (the only bounds parser in the repo missing -? — a11y.py, ecr_trace.py, dashboard.py, and crawl.py all parse signed integers).

Because negative signs are dropped and bounds are not checked against the viewport:

  • An off-screen carousel item with bounds="[-900,400][-100,600]" (true centre (-500, 500)) is printed as - button "Hidden Left Card" centre=(500,500), creating a phantom tap target in the middle of the screen.
  • A partially visible item with bounds="[-200,700][400,900]" has its centre shifted right from (100, 800) to (300, 800).
  • Zero-size ([0,0][0,0]) and off-screen ([100,2600][980,2800]) nodes are listed as tappable elements.
  • Embedded newlines in text or content-desc (e.g. "Send\nTab 2 of 3") break the one-element-per-line listing.

Solution

  • Extract elements(root, w, h) in scripts/android/screen.py (with main(argv=None) under if __name__ == "__main__": and from PIL import Image inside main(), matching scripts/web/screen.py so unit tests run cleanly without Pillow).
  • Parse signed coordinates with r"-?\d+", skip zero-size/inverted bounds (x2 <= x1 or y2 <= y1), and skip elements whose centre (cx, cy) falls outside the physical screen viewport (0 <= cx <= w and 0 <= cy <= h) (matching scripts/ios/screen.py and scripts/web/page_js.py, using w, h = img.size before the half-size resize).
  • Normalize text and content-desc with " ".join((...).split()) so multiline labels stay on one line and whitespace-only text falls back to content-desc.
  • Add offline unit tests and a stub-adb CLI test in tests/test_android_screen.py, update tests/test_ecr_replay.py to invoke elements() directly, and add a line to CHANGELOG.md (## Unreleased).

Verification

  • /usr/bin/python3 -m unittest discover -s tests -q (Python 3.9.6): 275 tests OK (3 opt-in Playwright tests skipped)
  • No-Pillow CI simulation (PIL masked): 8/8 unit tests pass (only stub-adb Pillow test skipped)
  • Python 3.9 AST syntax check on all touched files: OK

@pierridotite
pierridotite merged commit 6e37206 into pierridotite:main Nov 26, 2026
2 checks passed
@pierridotite

Copy link
Copy Markdown
Owner

Merged, thanks! Good catch on the missing minus sign, that phantom button in the middle of the screen was a nasty one. I also ran the replay check on an emulator after the merge and it still passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants