Unreviewed. Update W3C WebDriver imported tests.
[WebKit-https.git] / WebDriverTests / imported / w3c / webdriver / tests / state / is_element_selected.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
8 alert_doc = inline("<script>window.alert()</script>")
9 check_doc = inline("<input id=checked type=checkbox checked/><input id=notChecked type=checkbox/>")
10 option_doc = inline("""<select>
11                         <option id=notSelected>r-</option>
12                         <option id=selected selected>r+</option>
13                        </select>
14                     """)
15
16
17 # 13.1 Is Element Selected
18
19 def test_no_browsing_context(session, create_window):
20     # 13.1 step 1
21     session.window_handle = create_window()
22     session.close()
23
24     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/selected"
25                                     .format(session_id=session.session_id,
26                                             element_id="foo"))
27
28     assert_error(result, "no such window")
29
30
31 def test_handle_prompt_dismiss(new_session, add_browser_capabilites):
32     # 13.1 step 2
33     _, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "dismiss"})}})
34     session.url = inline("<input id=foo>")
35     element = session.find.css("#foo", all=False)
36
37     create_dialog(session)("alert", text="dismiss #1", result_var="dismiss1")
38
39     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/selected"
40                                     .format(session_id=session.session_id,
41                                             element_id=element.id))
42
43     assert_success(result, False)
44     assert_dialog_handled(session, "dismiss #1")
45
46     create_dialog(session)("confirm", text="dismiss #2", result_var="dismiss2")
47
48     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/selected"
49                                     .format(session_id=session.session_id,
50                                             element_id=element.id))
51
52     assert_success(result, False)
53     assert_dialog_handled(session, "dismiss #2")
54
55     create_dialog(session)("prompt", text="dismiss #3", result_var="dismiss3")
56
57     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/selected"
58                                     .format(session_id=session.session_id,
59                                             element_id=element.id))
60
61     assert_success(result, False)
62     assert_dialog_handled(session, "dismiss #3")
63
64
65 def test_handle_prompt_accept(new_session, add_browser_capabilites):
66     # 13.1 step 2
67     _, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "accept"})}})
68     session.url = inline("<input id=foo>")
69     element = session.find.css("#foo", all=False)
70
71     create_dialog(session)("alert", text="dismiss #1", result_var="dismiss1")
72
73     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/selected"
74                                     .format(session_id=session.session_id,
75                                             element_id=element.id))
76
77     assert_success(result, False)
78     assert_dialog_handled(session, "dismiss #1")
79
80     create_dialog(session)("confirm", text="dismiss #2", result_var="dismiss2")
81
82     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/selected"
83                                     .format(session_id=session.session_id,
84                                             element_id=element.id))
85
86     assert_success(result, False)
87     assert_dialog_handled(session, "dismiss #2")
88
89     create_dialog(session)("prompt", text="dismiss #3", result_var="dismiss3")
90
91     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/selected"
92                                     .format(session_id=session.session_id,
93                                             element_id=element.id))
94
95     assert_success(result, False)
96     assert_dialog_handled(session, "dismiss #3")
97
98
99 def test_handle_prompt_missing_value(session):
100     # 13.1 step 2
101     session.url = inline("<input id=foo>")
102     element = session.find.css("#foo", all=False)
103
104     create_dialog(session)("alert", text="dismiss #1", result_var="dismiss1")
105
106     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/selected"
107                                     .format(session_id=session.session_id,
108                                             element_id=element.id))
109
110     assert_error(result, "unexpected alert open")
111     assert_dialog_handled(session, "dismiss #1")
112
113     create_dialog(session)("confirm", text="dismiss #2", result_var="dismiss2")
114
115     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/selected"
116                                     .format(session_id=session.session_id,
117                                             element_id=element.id))
118
119     assert_error(result, "unexpected alert open")
120     assert_dialog_handled(session, "dismiss #2")
121
122     create_dialog(session)("prompt", text="dismiss #3", result_var="dismiss3")
123
124     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/selected"
125                                     .format(session_id=session.session_id,
126                                             element_id=element.id))
127
128     assert_error(result, "unexpected alert open")
129     assert_dialog_handled(session, "dismiss #3")
130
131
132 def test_element_stale(session):
133     # 13.1 step 4
134     session.url = check_doc
135     element = session.find.css("#checked", all=False)
136     session.refresh()
137     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/selected"
138                                     .format(session_id=session.session_id,
139                                             element_id=element.id))
140
141     assert_error(result, "stale element reference")
142
143
144 def test_element_checked(session):
145     # 13.1 step 5
146     session.url = check_doc
147     element = session.find.css("#checked", all=False)
148     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/selected"
149                                     .format(session_id=session.session_id,
150                                             element_id=element.id))
151
152     assert_success(result, True)
153
154
155 def test_checkbox_not_selected(session):
156     # 13.1 step 5
157     session.url = check_doc
158     element = session.find.css("#notChecked", all=False)
159     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/selected"
160                                     .format(session_id=session.session_id,
161                                             element_id=element.id))
162
163     assert_success(result, False)
164
165
166 def test_element_selected(session):
167     # 13.1 step 5
168     session.url = option_doc
169     element = session.find.css("#selected", all=False)
170     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/selected"
171                                     .format(session_id=session.session_id,
172                                             element_id=element.id))
173
174     assert_success(result, True)
175
176
177 def test_element_not_selected(session):
178     # 13.1 step 5
179     session.url = option_doc
180     element = session.find.css("#notSelected", all=False)
181     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/selected"
182                                     .format(session_id=session.session_id,
183                                             element_id=element.id))
184
185     assert_success(result, False)