Skip to content

fix(webdriverio): Misfound elements when using WebDriver BiDi#13798

Merged
christian-bromann merged 1 commit intowebdriverio:mainfrom
nextlevelbeard:fix/13556-misfound-elem-bidi
Oct 25, 2024
Merged

fix(webdriverio): Misfound elements when using WebDriver BiDi#13798
christian-bromann merged 1 commit intowebdriverio:mainfrom
nextlevelbeard:fix/13556-misfound-elem-bidi

Conversation

@nextlevelbeard
Copy link
Member

Proposed changes

Fixes #13556

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

Reviewers: @webdriverio/project-committers

@nextlevelbeard nextlevelbeard changed the title fix(webdriverio): Misfound elements when using WebDriver BiDi, fixes #13556 fix(webdriverio): Misfound elements when using WebDriver BiDi Oct 24, 2024
@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 24, 2024

Open in Stackblitz

eslint-plugin-wdio

pnpm add https://pkg.pr.new/webdriverio/webdriverio/eslint-plugin-wdio@13798

@wdio/allure-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/allure-reporter@13798

@wdio/browser-runner

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/browser-runner@13798

@wdio/appium-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/appium-service@13798

@wdio/browserstack-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/browserstack-service@13798

@wdio/cli

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/cli@13798

@wdio/concise-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/concise-reporter@13798

@wdio/config

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/config@13798

@wdio/cucumber-framework

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/cucumber-framework@13798

@wdio/dot-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/dot-reporter@13798

@wdio/firefox-profile-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/firefox-profile-service@13798

@wdio/globals

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/globals@13798

@wdio/jasmine-framework

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/jasmine-framework@13798

@wdio/json-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/json-reporter@13798

@wdio/junit-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/junit-reporter@13798

@wdio/local-runner

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/local-runner@13798

@wdio/lighthouse-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/lighthouse-service@13798

@wdio/logger

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/logger@13798

@wdio/mocha-framework

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/mocha-framework@13798

@wdio/protocols

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/protocols@13798

@wdio/reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/reporter@13798

@wdio/repl

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/repl@13798

@wdio/runner

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/runner@13798

@wdio/sauce-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/sauce-service@13798

@wdio/shared-store-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/shared-store-service@13798

@wdio/smoke-test-cjs-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-cjs-service@13798

@wdio/smoke-test-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-reporter@13798

@wdio/smoke-test-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-service@13798

@wdio/spec-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/spec-reporter@13798

@wdio/static-server-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/static-server-service@13798

@wdio/sumologic-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/sumologic-reporter@13798

@wdio/types

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/types@13798

@wdio/testingbot-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/testingbot-service@13798

@wdio/utils

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/utils@13798

@wdio/webdriver-mock-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/webdriver-mock-service@13798

webdriver

pnpm add https://pkg.pr.new/webdriverio/webdriverio/webdriver@13798

webdriverio

pnpm add https://pkg.pr.new/webdriverio/webdriverio@13798

commit: 1515d8b

@nextlevelbeard
Copy link
Member Author

nextlevelbeard commented Oct 24, 2024

@christian-bromann
I cannot add tests for this because creating a proper test bed for this area of the code is proving tricky to me.
There's no mocks for ws and BiDi commands AFAIK. Creating the stale scenario described here is also an unknown.
Looking at few changes there are, I think its quick to see and understand how when BiDi command "browsingContext.locateNodes" throws an error and we fall back to a classic WebDriver call, we are disregarding the scope.

This was tested locally and I could check in real world E2E tests that the scenario presented in the original issue was gone.


Scenario DOM state:

<div id="bar">
<div id="foo">
    <div id="bar">

Element 1 (#foo) and element 2 (#bar) exist in the root of the DOM.
Element 3 (also a #bar) is nested inside the Element 1 (#foo), therefore we build a nested element to find them.
This part is important. The process fails because of the webdriverIO feature of nested elements.

const rootFoo = await $('#foo');
const rootBar = await $('#bar');

// Problem is when you do this
// If "rootFoo" becames stale, and WebDriver BiDi is on, it actually returns "rootBar"
const fakeNestedBar = await rootFoo.$('#bar'); 

// No problem finding the nested #bar here
const realNestedBar = await $('#foo #bar');

Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

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

This makes sense to me 👍 thanks a lot for this contribution!

@christian-bromann
Copy link
Member

@nextlevelbeard it seems like this change is impacting one of the e2e test, mind taking a look at adjusting the test if you think it corrected the expected behavior?

@nextlevelbeard
Copy link
Member Author

nextlevelbeard commented Oct 25, 2024

@nextlevelbeard it seems like this change is impacting one of the e2e test, mind taking a look at adjusting the test if you think it corrected the expected behavior?

@christian-bromann Seems to be unrelated to the changes, CI gives a timeout, it passes locally

it('can reload a session with new capabilities', async () => {
        expect(browser.capabilities.browserName).toBe('chrome')
        await browser.reloadSession({
            browserName: 'edge',
            'ms:edgeOptions': {
                args: ['headless', 'disable-gpu']
            }
        })
        expect(browser.capabilities.browserName).toContain('MicrosoftEdge')
    })
» /wdio/headless/reloadSession.e2e.ts
[chrome 130.0.6723.69 mac #0-2] reloadSession
[chrome 130.0.6723.69 mac #0-2]    ✓ can reload a session
[chrome 130.0.6723.69 mac #0-2]    ✓ can reload a session with new capabilities
[chrome 130.0.6723.69 mac #0-2]
[chrome 130.0.6723.69 mac #0-2] 2 passing (20s)

But apparently another user just reported a problem that seems related to this: #13789

@christian-bromann christian-bromann added the PR: Bug Fix 🐛 PRs that contain bug fixes label Oct 25, 2024
@christian-bromann christian-bromann merged commit 08b496c into webdriverio:main Oct 25, 2024
@wdio-bot
Copy link
Contributor

Hey nextlevelbeard 👋

Thank you for your contribution to WebdriverIO! Your pull request has been marked as an "Expensable" contribution.

We've sent you an email with further instructions on how to claim your expenses from our development fund.
⚠️ You seemed to have committed using an email address ending up with @users.noreply.github.com, if you don't receive the email please feel free to reach out to us at expense@webdriver.io or in the contributing channel on Discord.

We are looking forward to more contributions from you in the future 🙌

Have a nice day,
The WebdriverIO Team 🤖

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

Labels

Expensable $35 💸 PR: Bug Fix 🐛 PRs that contain bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🐛 Bug]: [v9 ][CRITICAL] Misfound elements when BiDi locators lose parent context and fall back to WebDriver Classic

3 participants