Unreviewed. Update W3C WebDriver imported tests.
[WebKit-https.git] / WebDriverTests / imported / w3c / webdriver / tests / user_prompts / send_alert_text.py
1 import pytest
2
3 from tests.support.asserts import assert_error, assert_success
4
5 def send_alert_text(session, body=None):
6     return session.transport.send("POST", "session/{session_id}/alert/text"
7                                   .format(session_id=session.session_id), body)
8
9
10 # 18.4 Send Alert Text
11
12 @pytest.mark.parametrize("text", [None, {}, [], 42, True])
13 def test_invalid_input(session, text):
14     # 18.4 step 2
15     session.execute_script("window.result = window.prompt(\"Enter Your Name: \", \"Name\");")
16     response = send_alert_text(session, {"text": text})
17     assert_error(response, "invalid argument")
18
19
20 def test_no_browsing_context(session, create_window):
21     # 18.4 step 3
22     session.window_handle = create_window()
23     session.close()
24     body = {"text": "Federer"}
25     response = send_alert_text(session, body)
26     assert_error(response, "no such window")
27
28
29 def test_no_user_prompt(session):
30     # 18.4 step 4
31     body = {"text": "Federer"}
32     response = send_alert_text(session, body)
33     assert_error(response, "no such alert")
34
35
36 def test_alert_element_not_interactable(session):
37     # 18.4 step 5
38     session.execute_script("window.alert(\"Hello\");")
39     body = {"text": "Federer"}
40     response = send_alert_text(session, body)
41     assert_error(response, "element not interactable")
42
43
44 def test_confirm_element_not_interactable(session):
45     # 18.4 step 5
46     session.execute_script("window.confirm(\"Hello\");")
47     body = {"text": "Federer"}
48     response = send_alert_text(session, body)
49     assert_error(response, "element not interactable")
50
51
52 def test_send_alert_text(session):
53     # 18.4 step 6
54     session.execute_script("window.result = window.prompt(\"Enter Your Name: \", \"Name\");")
55     body = {"text": "Federer"}
56     send_response = send_alert_text(session, body)
57     assert_success(send_response)
58     accept_response = session.transport.send("POST", "session/{session_id}/alert/accept"
59                                              .format(session_id=session.session_id))
60     assert_success(accept_response)
61     assert session.execute_script("return window.result") == "Federer"
62
63
64 def test_send_alert_text_with_whitespace(session):
65     # 18.4 step 6
66     session.execute_script("window.result = window.prompt(\"Enter Your Name: \", \"Name\");")
67     body = {"text": " Fed erer "}
68     send_response = send_alert_text(session, body)
69     assert_success(send_response)
70     accept_response = session.transport.send("POST", "session/{session_id}/alert/accept"
71                                              .format(session_id=session.session_id))
72     assert_success(accept_response)
73     assert session.execute_script("return window.result") == " Fed erer "