Skip to content

feat(core): add screen.on('dialog') for android alerts and permission prompts - #360

Open
gmegidish wants to merge 1 commit into
mainfrom
feat/dialog-events
Open

gmegidish wants to merge 1 commit into
mainfrom
feat/dialog-events

Conversation

@gmegidish

Copy link
Copy Markdown
Member

Adds Playwright-style dialog handling: screen.on('dialog', d => d.accept()). Android only for now; iOS comes next.

How it works

  • Screen wraps the driver's getViewHierarchy(). Every locator poll and expect() retry already fetches the tree (every 100ms), so with a listener registered each fetch also checks for a dialog, at no extra device cost.
  • When a new dialog appears, the handlers run and the tree is fetched again, so a dialog covering the tap target is handled well inside the 5s action timeout.
  • Each dialog fires once (keyed by type, title, message and buttons). Without a listener nothing changes.
  • Detection uses resource-ids from mobilecli's identifier, the same ids Appium's UiAutomator2 server uses:
    • app alerts: android:id/button1..3, :id/alertTitle, android:id/message
    • permission prompts: :id/permission_message, :id/permission_*_button (accept = first _allow_, dismiss = _deny_)

API

  • screen.on/once/off('dialog', handler)
  • Dialog: type() (alert/confirm/prompt/permission), isSystem(), title(), message(), buttons(), accept(promptText?), dismiss(), tap(name)
  • device.clearAppData(bundleId) → mobilecli device.apps.clear. On Android this also resets runtime permissions, including "don't ask again", so permission prompts show again on every run. Added to the driver protocol and both drivers.

accept(text) on a prompt finds the OK button again after typing, because the keyboard pushes the dialog up (410px on a Pixel 9a).

Docs: new guides/dialogs page.

Test plan

  • 18 new unit tests in dialog.test.ts; all 798 core unit tests pass
  • npm run lint
  • e2e/src/android/dialogs.test.ts (8 tests: confirm, prompt, tap by caption, delayed alert, alert covering a tap target, location/camera/notifications prompts) passes 3 runs in a row on a Pixel 9a emulator (API 37)
  • needs the Playground build from feat: app alerts and location/notifications permission requests on android playground#21 on CI devices before the Android e2e job can pass
  • iOS support

@coderabbitai

coderabbitai Bot commented Oct 1, 2026

Copy link
Copy Markdown

Warning

Review limit reached

  • Run on-demand review

This review includes 16 billable files and costs up to $4.00.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 2 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available. Your 57 included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Essentials

Run ID: d89acd1b-8881-41dd-b67f-b27a9a9a0460

📥 Commits

Reviewing files that changed from the base of the PR and between 0df696f and b754cac.

📒 Files selected for processing (16)
  • docs/sidebars.js
  • docs/src/guides/dialogs.md
  • e2e/src/android/dialogs.test.ts
  • packages/driver-mobilecli/src/driver.ts
  • packages/driver-mobilenext/src/driver.ts
  • packages/mobilewright-core/src/device.test.ts
  • packages/mobilewright-core/src/device.ts
  • packages/mobilewright-core/src/dialog.test.ts
  • packages/mobilewright-core/src/dialog.ts
  • packages/mobilewright-core/src/expect.test.ts
  • packages/mobilewright-core/src/index.ts
  • packages/mobilewright-core/src/locator.test.ts
  • packages/mobilewright-core/src/screen.test.ts
  • packages/mobilewright-core/src/screen.ts
  • packages/mobilewright/src/index.ts
  • packages/protocol/src/driver.ts

Comment @coderabbitai help to get the list of available commands.

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