Skip to content

Instantly share code, notes, and snippets.

@jimevans
Created January 12, 2021 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimevans/cddaa08392cf556eb2d08b1513623901 to your computer and use it in GitHub Desktop.
Save jimevans/cddaa08392cf556eb2d08b1513623901 to your computer and use it in GitHub Desktop.
@pytest.fixture
def test_shadow_page(inline, shadow_content):
return inline("""
<custom-shadow-element></custom-shadow-element>
<script>
customElements.define('custom-shadow-element',
class extends HTMLElement {{
constructor() {{
super();
this.attachShadow({{mode: 'open'}}).innerHTML = `
{{ {0} }}
`;
}}
}});
</script>""".format(shadow_content))
@pytest.mark.parametrize("using,value",
[("css selector", "#linkText"),
("link text", "full link text"),
("partial link text", "link text"),
("tag name", "a"),
("xpath", "//a")])
def test_find_element(session, test_shadow_page, using, value):
# Step 8 - 9
session.url = test_shadow_page("<div><a href=# id=linkText>full link text</a></div>")
custom_element = session.find.css("custom-shadow-element", all=False)
shadow_root = custom_element.shadow_root
response = find_element(session, shadow_root, using, value)
assert_success(response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment