Skip to content

fix: atomic FindAndClick for ID selectors + SendKeyActions fallback#40

Open
tomkoptel wants to merge 2 commits intodevicelab-dev:mainfrom
tomkoptel:fix/compose-id-tap-atomic
Open

fix: atomic FindAndClick for ID selectors + SendKeyActions fallback#40
tomkoptel wants to merge 2 commits intodevicelab-dev:mainfrom
tomkoptel:fix/compose-id-tap-atomic

Conversation

@tomkoptel
Copy link

Summary

Two fixes for Compose UI compatibility:

  1. DeviceLab tapOn: extend FindAndClick atomic path to ID-based selectors (not just text). Previously, ID taps used findElementForTap + Click(x,y) which suffers from stale coordinates when Compose recomposes between the find and click steps. Now ID taps use the same atomic Java call (find node + coordinate click in one round-trip) that text taps use.

  2. Both drivers inputText: when SendKeys fails on the active element (stale reference from Compose recomposition after keyboard appears), fall back to SendKeyActions (W3C key press simulation) which doesn't depend on element references.

These issues manifest when testing Jetpack Compose UIs where:

  • Tapping an EditText triggers recomposition (keyboard appears)
  • The DOM element reference becomes stale before SendKeys executes
  • Coordinate-based clicks use stale positions after layout shifts

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)

Changes Made

  1. pkg/driver/devicelab/commands_test.go - Extended mock with configurable findAndClickFunc, activeElementFunc, sendKeyActionsFunc. Added 4 tests:
    • TestTapOnIDSelectorUsesAtomicFindAndClick — verifies ID selectors use the atomic FindAndClick path
    • TestTapOnTextSelectorUsesAtomicFindAndClick — verifies text selectors use FindAndClick (existing behavior, previously untested)
    • TestInputTextSendKeysFallbackToSendKeyActions — SendKeys fails, falls back to SendKeyActions successfully
    • TestInputTextSendKeysFallbackAlsoFails — both fail, error message includes both errors
  2. pkg/driver/uiautomator2/commands_test.go - Added 2 tests:
    - TestInputTextSendKeysFallbackToSendKeyActions — same fallback scenario
    - TestInputTextSendKeysFallbackAlsoFails — same both-fail scenario
  3. pkg/driver/uiautomator2/driver_test.go - Fixed TestInputTextNoSelectorError — added POST /actions handler returning 500, so the SendKeyActions fallback also fails (matching the test's expectation of failure).

Related Issues

Fixes #(issue number)

Testing

  • Tests pass locally (make test)
  • Linting passes (make lint)
  • Added tests for new functionality
  • Tested manually with sample flows

Checklist

  • Code follows project style guidelines
  • Self-reviewed the code
  • Added/updated documentation as needed
  • No breaking changes (or documented if breaking)
  • CHANGELOG.md updated (for notable changes)

tomkoptel and others added 2 commits March 17, 2026 20:31
Two fixes for Compose UI compatibility:

1. DeviceLab tapOn: extend FindAndClick atomic path to ID-based selectors
   (not just text). Previously, ID taps used findElementForTap + Click(x,y)
   which suffers from stale coordinates when Compose recomposes between
   the find and click steps. Now ID taps use the same atomic Java call
   (find node + coordinate click in one round-trip) that text taps use.

2. Both drivers inputText: when SendKeys fails on the active element
   (stale reference from Compose recomposition after keyboard appears),
   fall back to SendKeyActions (W3C key press simulation) which doesn't
   depend on element references.

These issues manifest when testing Jetpack Compose UIs where:
- Tapping an EditText triggers recomposition (keyboard appears)
- The DOM element reference becomes stale before SendKeys executes
- Coordinate-based clicks use stale positions after layout shifts
…fallback

Cover the two new behaviors: ID-based taps using atomic FindAndClick path,
and SendKeys falling back to SendKeyActions on stale element errors.
Fix TestInputTextNoSelectorError to account for the new fallback behavior.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@omnarayan
Copy link
Contributor

@tomkoptel - Thank for such a good feature addition. We ll review and merge it

@tomkoptel
Copy link
Author

@omnarayan you are welcome 🤗 Please, do a review. I was playing with a tool and had issues with Compose UI written app. I've used Claude Opus to investigate an issue. The fix came from LLM, so this one is definitely needs to be reviewed carefully. Cheers!

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