d84339db6e6b5a79534646db3c08b9f9103949fb
[WebKit-https.git] / WebDriverTests / imported / w3c / webdriver / tests / state / get_element_property.py
1 from tests.support.asserts import assert_error, assert_dialog_handled, assert_success
2 from tests.support.inline import inline
3 from tests.support.fixtures import create_dialog
4
5 _input = inline("<input id=i1>")
6
7
8 # 13.3 Get Element Property
9
10 def test_no_browsing_context(session, create_window):
11     # 13.3 step 1
12     session.window_handle = create_window()
13     session.close()
14
15     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/property/id"
16                                     .format(session_id=session.session_id,
17                                             element_id="foo"))
18
19     assert_error(result, "no such window")
20
21
22 def test_handle_prompt_dismiss(new_session, add_browser_capabilites):
23     # 13.3 step 2
24     _, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "dismiss"})}})
25     session.url = inline("<input id=foo>")
26
27     create_dialog(session)("alert", text="dismiss #1", result_var="dismiss1")
28
29     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/property/id"
30                                     .format(session_id=session.session_id,
31                                             element_id="foo"))
32
33     assert_success(result, "foo")
34     assert_dialog_handled(session, "dismiss #1")
35
36     create_dialog(session)("confirm", text="dismiss #2", result_var="dismiss2")
37
38     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/property/id"
39                                     .format(session_id=session.session_id,
40                                             element_id="foo"))
41
42     assert_success(result, "foo")
43     assert_dialog_handled(session, "dismiss #2")
44
45     create_dialog(session)("prompt", text="dismiss #3", result_var="dismiss3")
46
47     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/property/id"
48                                     .format(session_id=session.session_id,
49                                             element_id="foo"))
50
51     assert_success(result, "foo")
52     assert_dialog_handled(session, "dismiss #3")
53
54
55
56 def test_handle_prompt_accept(new_session, add_browser_capabilites):
57     # 13.3 step 2
58     _, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "accept"})}})
59     session.url = inline("<input id=foo>")
60
61     create_dialog(session)("alert", text="dismiss #1", result_var="dismiss1")
62
63     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/property/id"
64                                     .format(session_id=session.session_id,
65                                             element_id="foo"))
66
67     assert_success(result, "foo")
68     assert_dialog_handled(session, "dismiss #1")
69
70     create_dialog(session)("confirm", text="dismiss #2", result_var="dismiss2")
71
72     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/property/id"
73                                     .format(session_id=session.session_id,
74                                             element_id="foo"))
75
76     assert_success(result, "foo")
77     assert_dialog_handled(session, "dismiss #2")
78
79     create_dialog(session)("prompt", text="dismiss #3", result_var="dismiss3")
80
81     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/property/id"
82                                     .format(session_id=session.session_id,
83                                             element_id="foo"))
84
85     assert_success(result, "foo")
86     assert_dialog_handled(session, "dismiss #3")
87
88
89 def test_handle_prompt_missing_value(session, create_dialog):
90     # 13.3 step 2
91     session.url = inline("<input id=foo>")
92
93     create_dialog(session)("alert", text="dismiss #1", result_var="dismiss1")
94
95     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/property/id"
96                                     .format(session_id=session.session_id,
97                                             element_id="foo"))
98
99     assert_error(result, "unexpected alert open")
100     assert_dialog_handled(session, "dismiss #1")
101
102     create_dialog(session)("confirm", text="dismiss #2", result_var="dismiss2")
103
104     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/property/id"
105                                     .format(session_id=session.session_id,
106                                             element_id="foo"))
107
108     assert_error(result, "unexpected alert open")
109     assert_dialog_handled(session, "dismiss #2")
110
111     create_dialog(session)("prompt", text="dismiss #3", result_var="dismiss3")
112
113     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/property/id"
114                                     .format(session_id=session.session_id,
115                                             element_id="foo"))
116
117     assert_error(result, "unexpected alert open")
118     assert_dialog_handled(session, "dismiss #3")
119
120 def test_element_not_found(session):
121     # 13.3 Step 3
122     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/property/id"
123                                     .format(session_id=session.session_id,
124                                             element_id="foo"))
125
126     assert_error(result, "no such element")
127
128
129 def test_element_stale(session):
130     # 13.3 step 4
131     session.url = _input
132     element = session.find.css("input", all=False)
133     session.refresh()
134     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/property/id"
135                                     .format(session_id=session.session_id,
136                                             element_id=element.id))
137
138     assert_error(result, "stale element reference")
139
140
141 def test_element_non_existent(session):
142     # 13.3 step 5-7
143     session.url = _input
144     element = session.find.css("input", all=False)
145     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/property/foo"
146                                     .format(session_id=session.session_id,
147                                             element_id=element.id))
148
149     assert_success(result, None)
150     assert None == session.execute_script("return arguments[0].foo",
151                                           args=[element])
152
153
154 def test_element(session):
155     # 13.3 step 5-7
156     session.url = inline("<input type=checkbox>")
157     element = session.find.css("input", all=False)
158     element.click()
159     assert None == session.execute_script("return arguments[0].hasAttribute('checked')",
160                                           args=[element])
161     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/property/id"
162                                     .format(session_id=session.session_id,
163                                             element_id=element.id))
164     assert_success(result, True)