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