Unreviewed. Update W3C WebDriver imported tests.
[WebKit-https.git] / WebDriverTests / imported / w3c / webdriver / tests / state / get_element_tag_name.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
6 # 13.6 Get Element Tag Name
7
8 def test_no_browsing_context(session, create_window):
9     # 13.6 step 1
10     session.window_handle = create_window()
11     session.close()
12
13     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/name"
14                                     .format(session_id=session.session_id,
15                                             element_id="foo"))
16
17     assert_error(result, "no such window")
18
19
20 def test_handle_prompt_dismiss(new_session, add_browser_capabilites):
21     # 13.6 step 2
22     _, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "dismiss"})}})
23     session.url = inline("<input id=foo>")
24     element = session.find.css("#foo", all=False)
25
26     create_dialog(session)("alert", text="dismiss #1", result_var="dismiss1")
27
28     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/name"
29                                     .format(session_id=session.session_id,
30                                             element_id=element.id))
31
32     assert_success(result, "input")
33     assert_dialog_handled(session, "dismiss #1")
34
35     create_dialog(session)("confirm", text="dismiss #2", result_var="dismiss2")
36
37     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/name"
38                                     .format(session_id=session.session_id,
39                                             element_id=element.id))
40
41     assert_success(result, "input")
42     assert_dialog_handled(session, "dismiss #2")
43
44     create_dialog(session)("prompt", text="dismiss #3", result_var="dismiss3")
45
46     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/name"
47                                     .format(session_id=session.session_id,
48                                             element_id=element.id))
49
50     assert_success(result, "input")
51     assert_dialog_handled(session, "dismiss #3")
52
53
54 def test_handle_prompt_accept(new_session, add_browser_capabilites):
55     # 13.6 step 2
56     _, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "accept"})}})
57     session.url = inline("<input id=foo>")
58     element = session.find.css("#foo", all=False)
59
60     create_dialog(session)("alert", text="dismiss #1", result_var="dismiss1")
61
62     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/name"
63                                     .format(session_id=session.session_id,
64                                             element_id=element.id))
65
66     assert_success(result, "input")
67     assert_dialog_handled(session, "dismiss #1")
68
69     create_dialog(session)("confirm", text="dismiss #2", result_var="dismiss2")
70
71     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/name"
72                                     .format(session_id=session.session_id,
73                                             element_id=element.id))
74
75     assert_success(result, "input")
76     assert_dialog_handled(session, "dismiss #2")
77
78     create_dialog(session)("prompt", text="dismiss #3", result_var="dismiss3")
79
80     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/name"
81                                     .format(session_id=session.session_id,
82                                             element_id=element.id))
83
84     assert_success(result, "input")
85     assert_dialog_handled(session, "dismiss #3")
86
87
88 def test_handle_prompt_missing_value(session):
89     # 13.6 step 2
90     session.url = inline("<input id=foo>")
91     element = session.find.css("#foo", all=False)
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}/name"
96                                     .format(session_id=session.session_id,
97                                             element_id=element.id))
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}/name"
105                                     .format(session_id=session.session_id,
106                                             element_id=element.id))
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}/name"
114                                     .format(session_id=session.session_id,
115                                             element_id=element.id))
116
117     assert_error(result, "unexpected alert open")
118     assert_dialog_handled(session, "dismiss #3")
119
120
121 def test_element_not_found(session):
122     # 13.6 Step 3
123     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/name"
124                                     .format(session_id=session.session_id,
125                                             element_id="foo"))
126
127     assert_error(result, "no such element")
128
129
130 def test_element_stale(session):
131     # 13.6 step 4
132     session.url = inline("<input id=foo>")
133     element = session.find.css("input", all=False)
134     session.refresh()
135     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/name"
136                                     .format(session_id=session.session_id,
137                                             element_id=element.id))
138
139     assert_error(result, "stale element reference")
140
141
142 def test_get_element_tag_name(session):
143     # 13.6 step 6
144     session.url = inline("<input id=foo>")
145     element = session.find.css("input", all=False)
146     result = session.transport.send("GET", "session/{session_id}/element/{element_id}/name"
147                                     .format(session_id=session.session_id,
148                                             element_id=element.id))
149     assert_success(result, "input")