Repository navigation
feat(pagefactory): support decorating By and AppiumBy fields - #2492
Open
hoanle0126 wants to merge 5 commits into
Open
hoanle0126 wants to merge 5 commits into
hoanle0126 wants to merge 5 commits into
Conversation
hoanle0126
requested review from
SrinivasanTarget,
mykola-mokhnach,
saikrishna321 and
valfirst
as code owners
November 2, 2026 15:58
mykola-mokhnach
left a comment
Contributor
There was a problem hiding this comment.
Review notes inline.
Contributor
Author
|
Thanks @mykola-mokhnach for the thorough review! I have updated the PR in
|
mykola-mokhnach
left a comment
Contributor
There was a problem hiding this comment.
AppiumFieldDecorator.java:117:elementByBuilderis now one instance shared by everydecoratecall (new field, previously a freshDefaultElementByBuilderper locator).decorateBymutates it withsetAnnotated(field)andsetAnnotated(null). If one decorator is used from two threads, for example parallel page initialisation, thread A'ssetAnnotated(null)infinallycan run while thread B is mid-build. B then gets an NPE or builds a locator from the wrong field. Should this be one builder perdecorateBycall, or synchronised?AppiumFieldDecorator.java:119: The two paths treat missing annotations differently. AContentMappedBy-typed field with no annotations is always replaced with aByIdOrName(fieldName)locator (seeunannotatedContentMappedByin the test), because that branch returns before thehasLocatorAnnotationscheck. A plainByfield in the same state is left alone. A user who assigns theContentMappedByfield in a constructor or setup method gets the value overwritten. Is that intended?AppiumFieldDecorator.java:130:unwrapSingleByreads the privatebysfield ofByChained/ByAllby reflection and falls back silently onReflectiveOperationException. Both classes live in this project, so a public accessor would avoid the reflection. A rename or refactor ofbyswould otherwise make the unwrap stop working with no signal, andcoerceToTypewould returnnull.AppiumFieldDecorator.java:153:hasLocatorAnnotationshard-codes the list of supported annotations separately from the builder. An annotation added to the builder later but missing from this list leavesByfieldsnull, becausedecorateByreturns early. Could the builder expose "has any locator annotation" so there is one source of truth?
hoanle0126
force-pushed
the
feat/pagefactory-by-fields
branch
from
November 2, 2026 21:28
36c20e8 to
342f11a
Compare
Contributor
Author
|
Thanks @mykola-mokhnach for the follow-up review! Updated in
|
mykola-mokhnach
left a comment
Contributor
There was a problem hiding this comment.
- Annotated
Byfields with an initial value are overwritten.@FindBy(id="x") private By loc = By.id("y");is replaced atinitElements. Only unannotated fields are preserved (preInitializedByin the test). Is overwriting intended now that the earlier "already initialised" guard is gone? The earlier thread on this was resolved based on that guard.
Contributor
Author
|
Thanks @mykola-mokhnach! Addressed all 5 points in b5dd09d:
|
mykola-mokhnach
left a comment
Contributor
There was a problem hiding this comment.
Inline comment only; no general findings this round.
mykola-mokhnach
approved these changes
Nov 4, 2026
Contributor
|
@valfirst could you please take look? |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes
Fixes #1940
ByandAppiumByfields inAppiumFieldDecoratorwhen annotated with Appium or Selenium locator annotations (@AndroidFindBy,@AndroidFindBys,@AndroidFindAll,@iOSXCUITFindBy,@iOSXCUITFindBys,@iOSXCUITFindAll,@FindBy,@FindBys,@FindAll).DefaultElementByBuilder.buildMobileBywhen only one locator is present (bys.length == 1) so single@AndroidFindBy/@iOSXCUITFindByannotations resolve directly toAppiumBy(e.g.AppiumBy.id(...),AppiumBy.accessibilityId(...)) rather than wrapping a 1-element array inByChained/ByAll.By/AppiumByfields untouched (nullreturned bydecorate) so pre-initializedByconstants on page objects are preserved.ByFieldDecorationTestcovering Android, iOS, browser/webview fallback,@HowToUseLocators,Widgetsub-fields, pre-initializedByfields, and incompatible subtype validation.Types of changes