Repository navigation
fix: support wildcard and type-variable list generics in page factory decorators - #2494
Open
hoanle0126 wants to merge 3 commits into
Open
hoanle0126 wants to merge 3 commits into
hoanle0126 wants to merge 3 commits into
Conversation
hoanle0126
requested review from
SrinivasanTarget,
mykola-mokhnach,
saikrishna321 and
valfirst
as code owners
November 5, 2026 03:58
mykola-mokhnach
left a comment
Contributor
There was a problem hiding this comment.
AppiumFieldDecorator.java:144: for a list typed with a type variable or wildcard, the widget class resolves to the declared upper bound, not the type the page is parameterised with. WithGenericPage<W extends SampleWidget>instantiated asGenericPage<FancyWidget>,extractWidgetClassreturnsSampleWidget, so the proxy holdsSampleWidgetinstances.for (FancyWidget w : page.typeVarWidgets)then throwsClassCastException. Any@FindBy,@HowToUseLocators,@WithTimeoutor@OverrideWidgetonFancyWidgetis silently ignored. Could the field's declaring class and the page instance's runtime type be used to resolve the concrete argument? If the bound is intended, it should be documented.AppiumFieldDecorator.java:117: lower-bounded wildcards (List<? super WebElement>, KotlinMutableList<in WebElement>) are skipped on purpose and asserted in tests. The field stays undecorated and null, so the first use throws an NPE with no hint why. AList<WebElement>proxy would be a valid value for it. Is skipping intentional, given the goal of supporting wildcard lists? If so, consider failing fast or logging.AppiumFieldDecorator.java:106: thevisitedset incollectElementClasses(and inisWebElementType) guards against cycles that can't occur. Bounds aren't walked through parameterized type arguments, and Java forbidsT extends U, U extends T. It adds aHashSetallocation and an extra parameter in each recursion for no benefit.AppiumFieldDecorator.java:77: generic resolution runs per field inisDecoratableList,decorateWidget,findHowToUseLocators,findTimeoutandWidgetByBuilder. Each call re-runsresolveListElementClasses, allocating a list and a set and doing reflection, so a page with many list fields walks the type tree about 4-5 times per field ininitElements. Resolving once indecorateand passing the result down would avoid that.
… per-field list types
Contributor
Author
|
Thanks for the thorough review @mykola-mokhnach! I have updated the PR in
|
mykola-mokhnach
left a comment
Contributor
There was a problem hiding this comment.
Re-reviewed at 6549e10. The earlier threads are addressed. A regression for resolved type variables and a few semantic questions remain, inline below.
Contributor
Author
|
Thanks for the follow-up review @mykola-mokhnach! Updated in b38fcca:
|
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
Closes #1257
When page objects are written in Kotlin, read-only list properties (
val items: List<WebElement>orval widgets: List<MyWidget>) are compiled to Java bytecode with upper-bounded wildcard generics (List<? extends WebElement>,List<? extends MyWidget>) because Kotlin'sList<out T>interface is declaration-site covariant. Previously, bothDefaultFieldDecoratorandAppiumFieldDecoratorrequired the parameterized type argument to be a direct class reference, leaving wildcard-typed element and widget lists undecorated.This PR updates the page factory decorators and locator builders to:
DefaultFieldDecorator.resolveListElementClassesand single-field type resolution intoDefaultFieldDecorator.resolveFieldClasses(protected static), unwrapping direct classes, nested parameterized types, upper- and lower-bounded wildcards, and type variables (resolving concrete type arguments declared on parameterized generic page superclasses first and retaining the type variable's declared upper bounds as fallback when a concrete element subtype is not an exact match inAVAILABLE_ELEMENT_CLASSES).? super WebElementand? super Widget, corresponding to Kotlin's contravariant mutable lists) in addition to upper-bounded wildcards, unlike upstream Selenium's decorator which only inspects upper bounds.Types of changes