{{ message }}
Repository navigation
Conversation
…tten commands and chained queries An overwritten command ran its hooks for the override, with the original command as first argument, and again for the original. A query chained on a promise ran them in the chain and again in the element. - overwriteCommand: the override runs the hooks once, with the arguments of the call, and gets the original without its wrapper (a query still chains). Element overrides (attachToElement) are applied to the commands before the element wraps them, so they also run after the implicit wait. List queries keep their hooks on the original: they run when it loads. - The chain proxy builds single-element queries without wrapCommand. - Each client keeps one reference to its commands without the wrapper (__rawProperties__), outside __propertiesObject__, which an element deep-copies.
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
Follow-up of #16096: overwritten commands and queries chained on a promise still ran the command hooks 2 to 4 times, and the override got the original command as
args[0]of its hooks.beforehook calls, headless Chrome (BiDi and Classic give the same result):main$('#box').$('span')$×3:#box,span,span#box,span$('#s').parentElement()/nextElement()/shadow$()$('#box').$('span').$('b')browser.overwriteCommand('getTitle', …)[<fn>],[][]browser.overwriteCommand('$', …)(as the Appium selector optimizer)[<fn>, '#s'],['#s']['#s']elem.overwriteCommand('getTagName', …)overwriteCommand('getText', …, { attachToElement: true })attachToElementoverrides, also on a$$()itemattachToElementoverride that does not call the original[<fn>][]attachToElementoverride (each instance)$$chains and overrides,$$()[i], browsing context overrides, multi-remote browser overwrites and chainsHow
overwriteCommand(browser, element, multi-remote): the override is wrapped once and gets the user's arguments. Its original is the command without its wrapper, fromlift(added and overwritten commands) or from the client's raw commands. The original of a query still chains (chainQuery), soorig(selector).getText()keeps working.attachToElementoverrides are applied to the element commands before the element wraps them, so the element wraps the override once, as browsing contexts already do (composeOverrides).$$,custom$$,shadow$$,react$$) keep the current model: their hooks run when the original loads the list.chainQuery) instead of wrapping it again.__rawProperties__), outside__propertiesObject__: an element deep-copies__propertiesObject__on each$(), so a raw command on each descriptor made$()8–11 % slower.Changed behavior
attachToElementruns after the implicit wait (and again after a stale element retry), like an element command fromaddCommand. Before, it ran before the wait.$/$$call once, with its selector (before, it ignored the pair with the function and measured the original).Docs:
CustomCommands.md, the v10 migration guide and thewdio-v10-migrationskill.How you tested
overwriteCommandHooks.test.ts(18), multi-remote (3),monad.test.tsmain, all pass with the PR; the 3$$guards pass on both. The 3 tests that chain on the original of$also failed on a first version of this PR, where the original did not chaincommand-hooks.test.ts(Chrome Classic and BiDi)mainwebdriverio,@wdio/utils,webdriver,@wdio/runner,@wdio/cli,@wdio/session,@wdio/appium-service,@wdio/browser-runnerheadlessFlagonmaintoo, locally)test:component$$()matcher tests fail in Chrome Canary 158, the same onmainbench:runnermocha-lists-quiet, 4 rounds in turns withmainmain) / 90–102 ms (PR): noise$()and element commands with hooks, in turns withmain$()min 0.445 / 0.451 ms,getText0.065 / 0.065 mstest:typings, d.ts,test:browser-lib, oxlint,docs:generate:en, docs checkTypes of changes
Checklist
Backport Request
v10and doesn't need to be back-portedReviewers: @webdriverio/project-committers