Skip to content

feat: add mapTestTagToResourceId setting for Compose testTag support - #791

Merged
mykola-mokhnach merged 5 commits into
appium:masterfrom
mykola-mokhnach:tag
Aug 12, 2026
Merged

feat: add mapTestTagToResourceId setting for Compose testTag support#791
mykola-mokhnach merged 5 commits into
appium:masterfrom
mykola-mokhnach:tag

Conversation

@mykola-mokhnach

Copy link
Copy Markdown
Contributor

Adds an opt-in mapTestTagToResourceId setting that maps Jetpack Compose's testTag semantics property onto the resource-id attribute, mirroring the behavior of Compose's own testTagsAsResourceId (which can only be set from within the app's own composable tree and cannot be toggled externally). Wired consistently into getAttribute, page source/XPath, and id-based find_element/find_elements so all locator paths agree once enabled.

Addresses appium/appium#19560.

Adds an opt-in mapTestTagToResourceId setting that maps Jetpack
Compose's testTag semantics property onto the resource-id attribute,
mirroring the behavior of Compose's own testTagsAsResourceId (which
can only be set from within the app's own composable tree and cannot
be toggled externally). Wired consistently into getAttribute,
page source/XPath, and id-based find_element/find_elements so all
locator paths agree once enabled.

Addresses appium/appium#19560.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@eglitise
eglitise requested a lite review from Copilot August 12, 2026 15:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Comment thread app/src/main/java/io/appium/uiautomator2/model/BySelectorHelper.java Outdated
Comment thread app/src/main/java/io/appium/uiautomator2/utils/ElementLocationHelpers.java Outdated
mykola-mokhnach and others added 3 commits August 12, 2026 18:41
Simplify the redundant empty-string check in BySelectorHelper (getResourceId
already returns null for an empty value), and throw ElementNotFoundException
instead of returning null when the testTag-backed id lookup finds nothing,
matching the ByXPath branch's behavior.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
rewriteIdLocator() unconditionally prepends the app package to a bare id
locator, which is only correct for real Android resource ids. Compose
testTags are never package-qualified, so with mapTestTagToResourceId
enabled, a bare testTag search (e.g. "loginButton") was being rewritten
into "com.example.app:id/loginButton" and would never match. Now the
id-based XPath lookup matches against both the raw and the rewritten
locator, so real resource-id autocompletion keeps working while testTag
lookups match the raw value.
The four By.ById branches across findElement/findElements (both context and
no-context overloads) had drifted into near-identical copies of the
mapTestTagToResourceId lookup logic. Extract findElementById/findElementsById
helpers, parameterized by the optional context, so there's a single place
that implements this behavior.
Move private/package-private helpers below the public API methods for
consistent method ordering, precalculate the raw XPath literal once in
resourceIdXPath instead of recomputing it per branch, and collapse the
duplicated argument in rewriteIdLocator's error message via positional
format specifiers.
@mykola-mokhnach
mykola-mokhnach merged commit 1d2d583 into appium:master Aug 12, 2026
9 of 11 checks passed
@mykola-mokhnach
mykola-mokhnach deleted the tag branch August 12, 2026 18:18
github-actions Bot pushed a commit that referenced this pull request Aug 12, 2026
## [10.6.0](v10.5.0...v10.6.0) (2026-08-12)

### Features

* add mapTestTagToResourceId setting for Compose testTag support ([#791](#791)) ([1d2d583](1d2d583))
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 10.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@KazuCocoa

Copy link
Copy Markdown
Member

Should

if (by instanceof By.ById) {
String locator = rewriteIdLocator((By.ById) by);
accessibleUiObject = searchRoot == null
? CustomUiDevice.getInstance().findObject(androidx.test.uiautomator.By.res(locator))
: searchRoot.getChild(androidx.test.uiautomator.By.res(locator));
be updated as well?

@mykola-mokhnach

Copy link
Copy Markdown
Contributor Author

Good catch — ElementsCache.restore() had its own copy of the By.ById handling that didn't account for mapTestTagToResourceId. Fixed in d942cc7 by reusing the same testTag-aware resolution helper used by ElementLocationHelpers.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants