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