Unreviewed. Update W3C WebDriver imported tests.
[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     element = session.find.css("#foo", all=False)
27
28     create_dialog(session)("alert", text="dismiss #1", result_var="dismiss1")
29
30     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/property/id"
31                                     .format(session_id=session.session_id,
32                                             element_id=element.id))
33
34     assert_success(result, "foo")
35     assert_dialog_handled(session, "dismiss #1")
36
37     create_dialog(session)("confirm", text="dismiss #2", result_var="dismiss2")
38
39     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/property/id"
40                                     .format(session_id=session.session_id,
41                                             element_id=element.id))
42
43     assert_success(result, "foo")
44     assert_dialog_handled(session, "dismiss #2")
45
46     create_dialog(session)("prompt", text="dismiss #3", result_var="dismiss3")
47
48     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/property/id"
49                                     .format(session_id=session.session_id,
50                                             element_id=element.id))
51
52     assert_success(result, "foo")
53     assert_dialog_handled(session, "dismiss #3")
54
55
56
57 def test_handle_prompt_accept(new_session, add_browser_capabilites):
58     # 13.3 step 2
59     _, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "accept"})}})
60     session.url = inline("<input id=foo>")
61     element = session.find.css("#foo", all=False)
62
63     create_dialog(session)("alert", text="dismiss #1", result_var="dismiss1")
64
65     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/property/id"
66                                     .format(session_id=session.session_id,
67                                             element_id=element.id))
68
69     assert_success(result, "foo")
70     assert_dialog_handled(session, "dismiss #1")
71
72     create_dialog(session)("confirm", text="dismiss #2", result_var="dismiss2")
73
74     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/property/id"
75                                     .format(session_id=session.session_id,
76                                             element_id=element.id))
77
78     assert_success(result, "foo")
79     assert_dialog_handled(session, "dismiss #2")
80
81     create_dialog(session)("prompt", text="dismiss #3", result_var="dismiss3")
82
83     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/property/id"
84                                     .format(session_id=session.session_id,
85                                             element_id=element.id))
86
87     assert_success(result, "foo")
88     assert_dialog_handled(session, "dismiss #3")
89
90
91 def test_handle_prompt_missing_value(session):
92     # 13.3 step 2
93     session.url = inline("<input id=foo>")
94     element = session.find.css("#foo", all=False)
95
96     create_dialog(session)("alert", text="dismiss #1", result_var="dismiss1")
97
98     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/property/id"
99                                     .format(session_id=session.session_id,
100                                             element_id=element.id))
101
102     assert_error(result, "unexpected alert open")
103     assert_dialog_handled(session, "dismiss #1")
104
105     create_dialog(session)("confirm", text="dismiss #2", result_var="dismiss2")
106
107     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/property/id"
108                                     .format(session_id=session.session_id,
109                                             element_id=element.id))
110
111     assert_error(result, "unexpected alert open")
112     assert_dialog_handled(session, "dismiss #2")
113
114     create_dialog(session)("prompt", text="dismiss #3", result_var="dismiss3")
115
116     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/property/id"
117                                     .format(session_id=session.session_id,
118                                             element_id=element.id))
119
120     assert_error(result, "unexpected alert open")
121     assert_dialog_handled(session, "dismiss #3")
122
123 def test_element_not_found(session):
124     # 13.3 Step 3
125     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/property/id"
126                                     .format(session_id=session.session_id,
127                                             element_id="foo"))
128
129     assert_error(result, "no such element")
130
131
132 def test_element_stale(session):
133     # 13.3 step 4
134     session.url = _input
135     element = session.find.css("input", all=False)
136     session.refresh()
137     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/property/id"
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_non_existent(session):
145     # 13.3 step 5-7
146     session.url = _input
147     element = session.find.css("input", all=False)
148     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/property/foo"
149                                     .format(session_id=session.session_id,
150                                             element_id=element.id))
151
152     assert_success(result, None)
153     assert None == session.execute_script("return arguments[0].foo",
154                                           args=[element])
155
156
157 def test_element(session):
158     # 13.3 step 5-7
159     session.url = inline("<input type=checkbox>")
160     element = session.find.css("input", all=False)
161     element.click()
162     assert None == session.execute_script("return arguments[0].hasAttribute('checked')",
163                                           args=[element])
164     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/property/id"
165                                     .format(session_id=session.session_id,
166                                             element_id=element.id))
167     assert_success(result, True)