Unreviewed. Update W3C WebDriver imported tests.
[WebKit-https.git] / WebDriverTests / imported / w3c / webdriver / tests / user_prompts / accept_alert.py
1 from tests.support.asserts import assert_error, assert_success
2 from tests.support.inline import inline
3
4
5 def accept_alert(session):
6     return session.transport.send("POST", "session/{session_id}/alert/accept"
7                                   .format(session_id=session.session_id))
8
9
10 # 18.2 Accept Alert
11
12 def test_no_browsing_context(session, create_window):
13     # 18.2 step 1
14     session.window_handle = create_window()
15     session.close()
16
17     response = accept_alert(session)
18     assert_error(response, "no such window")
19
20
21 def test_no_user_prompt(session):
22     # 18.2 step 2
23     response = accept_alert(session)
24     assert_error(response, "no such alert")
25
26
27 def test_accept_alert(session):
28     # 18.2 step 3
29     session.url = inline("<script>window.alert('Hello');</script>")
30     response = accept_alert(session)
31     assert_success(response)
32
33
34 def test_accept_confirm(session):
35     # 18.2 step 3
36     session.url = inline("<script>window.result = window.confirm('Hello');</script>")
37     response = accept_alert(session)
38     assert_success(response)
39     assert session.execute_script("return window.result") is True
40
41
42 def test_accept_prompt(session):
43     # 18.2 step 3
44     session.url = inline("<script>window.result = window.prompt('Enter Your Name: ', 'Federer');</script>")
45     response = accept_alert(session)
46     assert_success(response)
47     assert session.execute_script("return window.result") == "Federer"