feat: support named parameters for executeJs#24386
Draft
Artur- wants to merge 3 commits into
Draft
Conversation
Test Results 1 416 files - 4 1 416 suites - 4 1h 17m 53s ⏱️ - 2m 36s For more details on these errors, see this check. Results for commit ba38bc1. ± Comparison against base commit 6bad3ec. ♻️ This comment has been updated with latest results. |
Artur-
commented
May 20, 2026
Artur-
added a commit
that referenced
this pull request
May 20, 2026
Lead the keydown handler body and the listenOn delegate registration JS with `const name = $N;` lines, so the rest of each body reads in terms of `allowedKeys`, `requiredModifiers`, `resetFocus`, `preventDefault` and `locator`, `handler`, `locatorSource` instead of `$0`..`$4`. Once PR #24386 (issue #24385) lands these aliases can be replaced by `JsFunction.withParameter(name, value)` directly.
Add `withParameter(name, value)` to a new `PendingJavaScriptExecution`
subtype returned from `Element.executeJs` and `Page.executeJs`, so the
JavaScript expression can read values by name instead of `$0`, `$1`,
…:
element.executeJs("doSomething(foo)")
.withParameter("foo", "Some value");
The mechanism is purely server-side: each `withParameter` call appends
the value to the invocation's parameter list and prepends
`let <name>=$N;` to the expression. Positional `$0`/`$1`/... parameters
keep their meaning, and parameters cannot be added after the execution
has been sent to the browser. The same `withParameter(name, value)`
helper is added to `JsFunction`, where it captures the value and aliases
it in the body the same way.
`callJsFunction` keeps returning `PendingJavaScriptResult` so it
doesn't expose `withParameter`, matching the issue's request to scope
the feature to `executeJs` only.
Fixes #24385
Mockito.when(page.executeJs(...)).thenReturn(...) now requires PendingJavaScriptExecution instead of PendingJavaScriptResult since that's the new return type of executeJs.
Validation runs again when the invocation is serialised via JacksonCodec, so the explicit dry-run on every withParameter / addNamedParameter call just doubles the work without adding signal.
7185220 to
ba38bc1
Compare
|
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.



Add
withParameter(name, value)to a newPendingJavaScriptExecutionsubtype returned from
Element.executeJsandPage.executeJs, so theJavaScript expression can read values by name instead of
$0,$1,…:
The mechanism is purely server-side: each
withParametercall appendsthe value to the invocation's parameter list and prepends
let <name>=$N;to the expression. Positional$0/$1/... parameterskeep their meaning, and parameters cannot be added after the execution
has been sent to the browser. The same
withParameter(name, value)helper is added to
JsFunction, where it captures the value and aliasesit in the body the same way.
callJsFunctionkeeps returningPendingJavaScriptResultso itdoesn't expose
withParameter, matching the issue's request to scopethe feature to
executeJsonly.Fixes #24385