feat: support named parameters for executeJs#24386
Conversation
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.
Test Results 1 407 files - 4 1 407 suites - 4 1h 15m 44s ⏱️ - 3m 9s For more details on these errors, see this check. Results for commit 7185220. ± Comparison against base commit f3c71b4. ♻️ This comment has been updated with latest results. |
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.
|
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 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