-
-
Notifications
You must be signed in to change notification settings - Fork 211
Shadow dom #728
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
base: main
Are you sure you want to change the base?
Shadow dom #728
Changes from all commits
77760e2
708a79f
bb932b4
ca0d431
80f5959
d356e2f
f749e16
2bbd851
2804fe9
5aebe19
158f6aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| defmodule Wallaby.Integration.Browser.ShadowDomTest do | ||
| use Wallaby.Integration.SessionCase, async: true | ||
|
|
||
| alias Wallaby.Element | ||
|
|
||
| setup %{session: session} do | ||
| page = | ||
| session | ||
| |> visit("shadow_dom.html") | ||
|
|
||
| {:ok, page: page} | ||
| end | ||
|
|
||
| test "can find a shadow root", %{session: session} do | ||
| shadow_root = | ||
| session | ||
| |> find(Query.css("shadow-test")) | ||
| |> shadow_root() | ||
|
|
||
| assert %Element{} = shadow_root | ||
| end | ||
|
|
||
| test "can find elements within a shadow dom", %{session: session} do | ||
| element = | ||
| session | ||
| |> find(Query.css("shadow-test")) | ||
| |> shadow_root() | ||
| |> find(Query.css("#in-shadow")) | ||
|
|
||
| assert Element.text(%Element{} = element) == "I am in shadow" | ||
| end | ||
|
|
||
| test "can click elements within a shadow dom", %{session: session} do | ||
| element = | ||
| session | ||
| |> find(Query.css("shadow-test")) | ||
| |> shadow_root() | ||
| |> click(Query.css("#option1")) | ||
| |> click(Query.css("#option2")) | ||
|
|
||
| assert selected?(element, Query.css("#option2")) | ||
| end | ||
|
|
||
| test "does not return a shadow root when one does not exist", %{session: session} do | ||
| shadow_root = | ||
| session | ||
| |> find(Query.css("#outside-shadow")) | ||
| |> shadow_root() | ||
|
|
||
| refute shadow_root | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <html> | ||
| <head> | ||
| <script> | ||
| class ShadowTestElement extends HTMLElement { | ||
| connectedCallback() { | ||
| this.attachShadow({mode: 'open'}); | ||
| this.shadowRoot.innerHTML = ` | ||
| <div id="in-shadow">I am in shadow</div> | ||
| <form class="form" action="index.html" method="get"> | ||
| <input id="option1" type="radio" name="radios" value="option1" /> | ||
| <input id="option2" type="radio" name="radios" value="option2" /> | ||
| </form> | ||
| `; | ||
| } | ||
| } | ||
| window.customElements.define('shadow-test', ShadowTestElement); | ||
| </script> | ||
| </head> | ||
|
|
||
| <body> | ||
| <div id="outside-shadow">I am out of shadow</div> | ||
| <shadow-test></shadow-test> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1012,6 +1012,25 @@ defmodule Wallaby.Browser do | |
| ) | ||
| end | ||
|
|
||
| @doc """ | ||
| Finds and returns the shadow root for the given element. | ||
|
|
||
| Queries executed on the returned shadow root will be scoped to the root's shadow DOM. | ||
|
|
||
| ``` | ||
| session | ||
| |> find(Query.css("shadow-test")) | ||
| |> shadow_root() | ||
| |> find(Query.css("#in-shadow")) | ||
| ``` | ||
| """ | ||
| def shadow_root(%{driver: driver} = element) do | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add an |
||
| case driver.shadow_root(element) do | ||
| {:ok, element} -> element | ||
| {:error, _error} -> nil | ||
| end | ||
| end | ||
|
|
||
| @doc """ | ||
| Validates that the query returns a result. This can be used to define other | ||
| types of matchers. | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -410,6 +410,9 @@ defmodule Wallaby.Chrome do | |||
| defdelegate accept_prompt(session, input, fun), to: WebdriverClient | ||||
| @doc false | ||||
| defdelegate dismiss_prompt(session, fun), to: WebdriverClient | ||||
| @doc false | ||||
| defdelegate shadow_root(element), to: WebdriverClient | ||||
|
|
||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| @doc false | ||||
| defdelegate parse_log(log), to: Wallaby.Chrome.Logger | ||||
|
|
||||
|
|
||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -180,6 +180,11 @@ defmodule Wallaby.Driver do | |||||
| @callback find_elements(Session.t() | Element.t(), Query.compiled()) :: | ||||||
| {:ok, [Element.t()]} | {:error, reason} | ||||||
|
|
||||||
| @doc """ | ||||||
| Invoked to find shadow root of given element | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| """ | ||||||
| @callback shadow_root(Element.t()) :: {:ok, Element.t()} | {:error, reason} | ||||||
|
|
||||||
| @doc """ | ||||||
| Invoked to execute JavaScript in the browser. | ||||||
| """ | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.