-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
selector cannot select within an open shadowDOM #109
Comments
1 could look like class FooBar extends PageObject {
myButton = shadowSelector(‘custom-element’, ‘button’);
} 2 might look like class FooBar extends PageObject {
shadow = shadowSelector(‘custom-element’, class extends PageObject {
theButton = selector(‘button’);
});
get myButton() {
return this.shadow.theButton;
}
} 3 might look like: class FooBar extends PageObject {
myButton = selector(‘custom-element::shadow button’);
} |
It is actually not possible to wrap a ShadowRoot with a PageObject at the moment making this a blocker for using fractal for custom elements. class FooBar extends PageObject {
get shadow() {
return new PageObject(this.element.shadowRoot);
}
} |
Thanks for the issue! In my mind, I've broken this down into two separate issues:
|
Oh, and have a look at #110 and tell me what you think -- as long as you don't see any glaring issues, I'll merge it and cut a release so you can try it out. |
Looks like #110 would satisfy the feature. If we were to explore options for a more declarative API what are your thoughts on that interface? How do you feel about introducing an unofficial |
I'd definitely like to explore other options first. That would require doing our own parsing of selectors, which is something I'd very much like to avoid.
|
v0.5.0 released with low-level shadow DOM support |
Just out of curiosity would an API like this work? class FooBar extends PageObject {
somethingWhichHasAShadowRoot = shadowSelector('.something', class extends PageObject {
somethingWithinTheShadowRoot = selector('.something-inside');
});
} Then it would look like Or if that doesn't support lazy evaluation maybe a different class FooBar extends PageObject {
somethingWhichHasAShadowRoot = selector('.something', class extends ShadowPageObject {
somethingWithinTheShadowRoot = selector('.something-inside');
});
} |
@sukima I've put some thought into this, and need to put some more in, but I think making the shadow DOM vs regular DOM distinction on the page object that is the root of the shadow DOM may not be the way to go. If I want to be able to interact with both the element's shadow DOM and its children/descendants in the regular DOM, I'd have to create two separate page objects, e.g. class FooBar extends PageObject {
somethingWhichHasAShadowRoot = shadowSelector('.something', class extends PageObject {
somethingInTheShadowDOM = selector('.something-shadowy');
});
somethingWhichHasAShadowRoot2 = selector('.something', class extends PageObject {
somethingInTheRegularDOM = selector('.something-not-shadowy');
});
} and that seems counter to how we like to model our DOMs with page objects. I think what we probably want it to end up looking like is something more like class FooBar extends PageObject {
somethingWhichHasAShadowRoot = selector('.something', class extends PageObject {
somethingInTheShadowDOM = shadowSelector('.something-shadowy');
somethingInTheRegularDOM = selector('.something-not-shadowy');
});
} where This forces you to define a page object for the element with the shadow root, which maybe isn't a huge problem, but also might not be ideal. So maybe it would make sense to overload class FooBar extends PageObject {
somethingWhichHasAShadowRoot = selector('.something', class extends PageObject {
somethingInTheShadowDOM = shadowSelector('.something-shadowy');
});
somethingInTheShadowDOM2 = shadowSelector('.something', '.something-shadowy');
}
I'll have to think some more about the feasibility of implementing an API like this, but hopefully it's doable. But just from an API design standpoint, what do you think? |
@bendemboski Apologies, this dropped below the fold. I think we are on the same page. Some thoughts:
The suggestions you gave would work for my purposes and if you are still comfortable with that proposed interface I would not mind looking deeper into the current source code―no guarantees I'll get something done though 😉 |
The current
querySelector
/querySelectorAll
doesn’t have a syntax to select within a shadowDOM.Some solutions:
shadowSelector
that knows to use theelement.shadowRoot.querySelector()
. But we would need to allow the helper to take a second query for scoping.this.element.shadowRoot.querySelector
.:shadow
to allow diving into from theselector
helper like:myButton = selector(‘foo-bar::shadow button’);
But that means parsing the string before passing it toquerySelector
.The text was updated successfully, but these errors were encountered: