Skip to content

(webdriverio): implement deep lookup with Bidi#12446

Merged
christian-bromann merged 8 commits intomainfrom
cb/deep-lookup
Mar 12, 2024
Merged

(webdriverio): implement deep lookup with Bidi#12446
christian-bromann merged 8 commits intomainfrom
cb/deep-lookup

Conversation

@christian-bromann
Copy link
Member

Proposed changes

With Bidi we can now inject a script to collect all initiated shadow roots in order to do a deep lookup effeciently.

Types of changes

  • Polish (an improvement for an existing feature)
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (improvements to the project's docs)
  • Specification changes (updates to WebDriver command specifications)
  • Internal updates (everything related to internal scripts, governance documentation and CI files)

Checklist

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)
  • I have added proper type definitions for new commands (if appropriate)

Backport Request

//: # (The current main branch is the development branch for WebdriverIO v9. If your change should be released to the current major version of WebdriverIO (v8), please raise another PR with the same changes against the v8 branch.)

  • This change is solely for v9 and doesn't need to be back-ported
  • Back-ported PR at #XXXXX

Further comments

Thanks @erwinheitzman for coming up with this idea.

Reviewers: @webdriverio/project-committers

@christian-bromann christian-bromann added PR: New Feature 🚀 PRs that contain new features v9 labels Mar 7, 2024
@christian-bromann christian-bromann marked this pull request as ready for review March 9, 2024 06:00
node as any as HTMLElement
).then((wasFound) => wasFound ? host : undefined),
...shadowRoots.map((shadowRootId) => (
browser.execute(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is never awaited and I think that might cause race conditions when the promise is not yet resolved and is put into the execute function

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't need to because it is a parameter within a Promise.all which takes a list of promises and resolves them. It is done this way so that all look ups happen in parallel.

...shadowRoots.map(
(shadowRootNodeId) => browser.findElementsFromShadowRoot(shadowRootNodeId, using, value)
.then(
elementPromiseHandler<ElementReference[]>(handle, shadowRootManager, shadowRootNodeId),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we run this only once, store the result and pass it on twice instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this would make it that much more efficient, especially since elements change, show up or disappear. It makes it easier to just query elements again rather than caching results and worrying about when to clear the cache etc.

@erwinheitzman
Copy link
Member

Since we do a lot of mapping I am wondering if it would make sense to use a WeakMap in some places, what do you think?

@christian-bromann
Copy link
Member Author

what do you think?

Yeah, I always forget this exists. shadowRootManager and #shadowRootElements can definitely be WeakMaps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: New Feature 🚀 PRs that contain new features v9

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants