-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathget.py
More file actions
115 lines (77 loc) · 3.58 KB
/
get.py
File metadata and controls
115 lines (77 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import pytest
from webdriver import WebElement
from tests.support.asserts import assert_error, assert_same_element, assert_success
def get_shadow_root(session, element_id):
return session.transport.send(
"GET", "session/{session_id}/element/{element_id}/shadow".format(
session_id=session.session_id,
element_id=element_id))
def test_no_top_browsing_context(session, closed_window):
original_handle, element = closed_window
response = get_shadow_root(session, element.id)
assert_error(response, "no such window")
response = get_shadow_root(session, "foo")
assert_error(response, "no such window")
session.window_handle = original_handle
response = get_shadow_root(session, element.id)
assert_error(response, "no such element")
def test_no_browsing_context(session, closed_frame):
response = get_shadow_root(session, "foo")
assert_error(response, "no such window")
def test_no_such_element_with_invalid_value(session):
element = WebElement(session, "foo")
response = get_shadow_root(session, element.id)
assert_error(response, "no such element")
@pytest.mark.parametrize("closed", [False, True], ids=["open", "closed"])
def test_no_such_element_from_other_window_handle(session, inline, closed):
session.url = inline("<div id='parent'><p/>")
element = session.find.css("#parent", all=False)
new_handle = session.new_window()
if closed:
session.window.close()
session.window_handle = new_handle
response = get_shadow_root(session, element.id)
assert_error(response, "no such element")
@pytest.mark.parametrize("closed", [False, True], ids=["open", "closed"])
def test_no_such_element_from_other_frame(session, get_test_page, closed):
session.url = get_test_page(as_frame=True)
frame = session.find.css("iframe", all=False)
session.switch_to_frame(frame)
element = session.find.css("div", all=False)
session.switch_to_parent_frame()
if closed:
session.execute_script("arguments[0].remove();", args=[frame])
response = get_shadow_root(session, element.id)
assert_error(response, "no such element")
@pytest.mark.parametrize("as_frame", [False, True], ids=["top_context", "child_context"])
def test_stale_element_reference(session, stale_element, as_frame):
element = stale_element("custom-element", as_frame=as_frame)
result = get_shadow_root(session, element.id)
assert_error(result, "stale element reference")
def test_get_shadow_root(session, get_test_page):
session.url = get_test_page()
host_element = session.find.css("custom-element", all=False)
response = get_shadow_root(session, host_element.id)
value = assert_success(response)
assert isinstance(value, dict)
assert "shadow-6066-11e4-a52e-4f735466cecf" in value
expected_host = session.execute_script("""
return arguments[0].shadowRoot.host
""", args=(host_element,))
assert_same_element(session, host_element, expected_host)
@pytest.mark.parametrize(
"html, selector",
[
("<div><p>no shadow root</p></div>", "div"),
("<select></select>", "select"),
("<video></video>", "video"),
],
ids=["div", "select", "video"],
)
def test_no_user_agent_shadow_root(session, inline, html, selector):
session.url = inline(html)
element = session.find.css(selector, all=False)
# Make sure user-agent shadow roots are not leaked by get shadow root
# (eg Firefox uses shadow dom to implement the select widget).
response = get_shadow_root(session, element.id)
assert_error(response, "no such shadow root")