Closed AutomatedTester closed 10 months ago
As I am investigating this, I found that the getShadowRoot
command should return a ShadowRoot
instance and officially, there are only two methods that are supposed to work on it, findElement
and findElement
(methods like find
and findAll
can be added as aliases for these methods for better syntax).
But the problem is that right now we treat the shadow root as an instance of WebElement
instead of ShadowRoot
, which provides a lot of other methods like property
and when we use some of these methods directly on the shadow root (being treated as a WebElement
right now), it works on them, even on Firefox.
Try this:
describe("shadow root example",
it("can inspect a shadow root", async (browser) => {
browser.navigateTo("https://mdn.github.io/web-components-examples/word-count-web-component/");
const shadowRoot = await browser.getShadowRoot("body > article:nth-child(2) > p:nth-child(4)")
// const shadowRootLabel = await shadowRoot.find("span")
await expect(shadowRoot.property('innerHTML')).to.include("Words: 212")
})
)
and it will pass on all browsers, while the property
method is not officially supported on ShadowRoot
.
So, while the correct way to solve this seems to be to treat ShadowRoot as the instance of ShadowRoot class instead of an instance of WebElement
, but doing so might break the behaviour for some users as many methods which currently work on a ShadowRoot in Nightwatch will stop working.
So, what I propose it to solve the issue where getShadowRoot()
is not working in Firefox (which can be solved by hitting /element/{element id)/shadow
endpoint instead of executing a script) but still treat it as a WebElement
for further chaining of operations.
I think it's fine to special case it here so we can maintain good chaining
Description of the bug/issue
When searching from a shadow root Nightwatch should use the Find from shadow root endpoints
Steps to reproduce
Run the test below
Sample test
Command to run
Verbose Output
Nightwatch Configuration
Nightwatch.js Version
2.6.21, 3.3.0
Node Version
18
Browser
Firefox 120, Chrome 119
Operating System
No response
Additional Information
No response