nightwatchjs / nightwatch

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
https://nightwatchjs.org
MIT License
11.79k stars 1.31k forks source link

nightwatch 2.5.0 Issue: shadowRootEl.findElement is not a function Error #3480

Open praveenrp1610 opened 1 year ago

praveenrp1610 commented 1 year ago

Description of the bug/issue

When I navigate validate element inside an shadow element with nightwatch 2.5.0

const shadowRootEl = await browser.useXpath().getShadowRoot('//shadow root container') await shadowRootEl.findElement(some element);

Then I get the error as shadowRootEl.findElement is not a function

Steps to reproduce

When I validate element inside an element with nightwatch 2.5.0

const shadowRootEl = await browser.useXpath().getShadowRoot('//shadow root container') await shadowRootEl.findElement(some element);

Then I get the error as shadowRootEl.findElement is not a function

Sample test

shadowElementFinder: async function (element) {
        await browser.pause(1000)
        const shadowRootEl = await browser.useXpath().getShadowRoot('//vat-checker')
        await browser.pause(1000)
        return await shadowRootEl.findElement(element);
    }

assertWizardHeader: async function(headerTitle) {
        const header = await helperWrapper.shadowElementFinder('h1')
        await browser.expect.element(header).text.to.equal(headerTitle)
    },

Command to run

No response

Verbose Output

TypeError: shadowRootEl.findElement is not a function
           at Object.shadowElementFinder (/app/step-definitions/wrappers/helper.js:6:35)
           at async Object.assertWizardHeader (/app/step-definitions/wrappers/ui-container-vat-checker.js:18:24)
           at async Object.assertWizardLoaded (/app/step-definitions/wrappers/ui-container-vat-checker.js:14:9)
           at async World.<anonymous> (/app/step-definitions/ui-container-vat-checker.js:9:5)
   - And I see the header # step-definitions/ui-container-vat-checker.js:12

Nightwatch Configuration

No response

Nightwatch.js Version

2.5.0

Node Version

No response

Browser

Chrome 107.0.3

Operating System

Linux Docker container

Additional Information

This is working with 2.4.1 but not with latest version

github-actions[bot] commented 1 year ago

Thank you for setting this as an enhancement. One of the product folk will triage this again to help see when we can fit this in an upcoming sprint.

AutomatedTester commented 1 year ago

This looks like it could be a mix and match of Selenium and Nightwatch here and we might not expose the ShadowRoot object here.

We are going to need to expose findElement. As a workaround if you use find instead of findElement it should do what you need.

praveenrp1610 commented 1 year ago

Hi David, Unfortunately, I have tried with find and that resulted in the same error

praveenrp1610 commented 1 year ago

The major issue with Nightwatch seems to ability to test anything with "SHADOW DOM "

Most of our products are switching to micro frontends that work on the shadow dom concept. I have tried Playwright as a POC comparison with Nightwatch and it does not have the same issue as Nightwatch.

Can you please prioritise this higher ?

beatfactor commented 1 year ago

Nightwatch does work fine with Shadow doms which are not closed. See this example (not yet updated to Nightwatch 2.5): https://github.com/nightwatchjs/nightwatch-examples/blob/main/tests/shadowRootExample.js

I'll look into it.