Skip to content

feat: add auto-wait and assertion commands#18

Open
tosh7 wants to merge 6 commits intomainfrom
feature/auto-wait-assertion
Open

feat: add auto-wait and assertion commands#18
tosh7 wants to merge 6 commits intomainfrom
feature/auto-wait-assertion

Conversation

@tosh7
Copy link
Copy Markdown
Owner

@tosh7 tosh7 commented Mar 24, 2026

Summary

  • Auto-wait: Element-level stability detection before tap (replaces coarse hash-based retry for semantic selectors)
  • Assertion: era assert command for UI state verification with polling + timeout, exit code 0/1 for shell scripting

Changes

Phase 4a: Auto-wait (wait.rs)

  • wait_for_element(): Polls UI tree until target element is visible + enabled + frame-stable (2 consecutive polls match)
  • tap_element_with_wait(): Pre-tap wait → tap → post-tap change detection
  • Frame gains PartialEq for stability comparison
  • handle_tap uses auto-wait for --text/--type selectors; coordinate mode retains existing tap_with_retry

Phase 4b: Assertion (assertion.rs)

  • Selector enum: Text, Type(String, Option<u32>), Ref(u32)
  • Condition enum: Visible, Hidden, Enabled, Disabled, TextEquals, TextContains, Count
  • assert_condition(): Polling loop (500ms interval, configurable timeout)
  • era assert CLI with subcommands: visible, hidden, enabled, disabled, text, count
  • SelectorArgs with #[command(flatten)] for reusable --text/--type/--index/--ref options

Usage examples

# Wait for element then tap (auto-wait)
era tap -d <device> --text "Login"

# Assert element is visible (5s timeout)
era assert -d <device> visible --text "Welcome"

# Assert element hidden (loading spinner gone)
era assert -d <device> --timeout 10000 hidden --text "Loading..."

# Assert text content
era assert -d <device> text --ref 5 --equals "Order Complete"

# Assert button count
era assert -d <device> count --type Button --expected 3

# Shell scripting
era assert -d $UDID visible --text "Login" && era tap -d $UDID --text "Login"

Test plan

  • All 246 tests pass (143 lib + 18 coordinate + 56 regression + 12 retry + 17 scale)
  • 33 assertion unit tests covering all conditions, selectors, and edge cases
  • Auto-wait stability detection tests
  • CLI parse tests for assert subcommands

tosh7 added 6 commits March 24, 2026 17:53
- Add --text option: find element by AXLabel/AXValue (case-insensitive
  partial match) via live UI tree query
- Add --type/--index options: find element by type with optional 0-based
  index among matches
- Both tap and fill now support 4 target modes: -x/-y, --ref, --text,
  --type (mutually exclusive via clap conflicts)
- Fill --target for text-based element search, --type/--index for type
- Add find_by_text() and find_by_type_index() to snapshot module
- resolve_live_element() helper queries idb describe-all on the fly
Add era session connect/list/disconnect/disconnect-all commands.
Sessions store UDID, device name, and auto-detected scale factor
in ~/.era/sessions.json. Existing commands (tap, snapshot, fill,
swipe, tap-region) gain --session option as alternative to --device.
When neither is specified, the default session is used.
…tor-session

# Conflicts:
#	src/cli/mod.rs
#	tests/regression.rs
Add wait module with Playwright-inspired auto-wait polling that
repeatedly queries the UI tree until a matching element appears or
timeout is reached. Integrates into CLI via --wait/--timeout flags
on tap and fill commands for --text/--type selectors.
Add assertion.rs with Condition enum (Visible/Hidden/Enabled/Disabled/
TextEquals/TextContains/Count), Selector enum, and polling-based
assert_condition() function. Add Assert CLI subcommand with shared
SelectorArgs via #[command(flatten)]. Exit code 0 for pass, 1 for fail.

Also fix Phase 4a integration issues: restore wait/timeout fields in
Tap/Fill commands, fix tuple access in auto-wait handler, fix
fill_element_with_wait (use wait_for_element + manual fill), fix
wait.rs type error in find_by_type.
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.

1 participant