Unreviewed. Update W3C WebDriver imported tests.
[WebKit-https.git] / WebDriverTests / imported / w3c / webdriver / tests / execute_script / user_prompts.py
1 import pytest
2
3 from webdriver import error
4
5
6 # 15.2 Executing Script
7
8 def test_handle_prompt_accept(new_session, add_browser_capabilites):
9     _, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "accept"})}})
10     session.execute_script("window.alert('Hello');")
11     with pytest.raises(error.NoSuchAlertException):
12         session.alert.accept()
13
14
15 def test_handle_prompt_dismiss(new_session, add_browser_capabilites):
16     _, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "dismiss"})}})
17     session.execute_script("window.alert('Hello');")
18     with pytest.raises(error.NoSuchAlertException):
19         session.alert.dismiss()
20
21
22 def test_handle_prompt_dismiss_and_notify(new_session, add_browser_capabilites):
23     _, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "dismiss and notify"})}})
24     with pytest.raises(error.UnexpectedAlertOpenException):
25         session.execute_script("window.alert('Hello');")
26     with pytest.raises(error.NoSuchAlertException):
27         session.alert.dismiss()
28
29
30 def test_handle_prompt_accept_and_notify(new_session, add_browser_capabilites):
31     _, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "accept and notify"})}})
32     with pytest.raises(error.UnexpectedAlertOpenException):
33         session.execute_script("window.alert('Hello');")
34     with pytest.raises(error.NoSuchAlertException):
35         session.alert.accept()
36
37
38 def test_handle_prompt_ignore(new_session, add_browser_capabilites):
39     _, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "ignore"})}})
40     with pytest.raises(error.UnexpectedAlertOpenException):
41         session.execute_script("window.alert('Hello');")
42     session.alert.dismiss()
43
44
45 def test_handle_prompt_default(new_session, add_browser_capabilites):
46     _, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({})}})
47     with pytest.raises(error.UnexpectedAlertOpenException):
48         session.execute_script("window.alert('Hello');")
49     with pytest.raises(error.NoSuchAlertException):
50         session.alert.dismiss()
51
52
53 def test_handle_prompt_twice(new_session, add_browser_capabilites):
54     _, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "accept"})}})
55     session.execute_script("window.alert('Hello');window.alert('Bye');")
56     # The first alert has been accepted by the user prompt handler, the second one remains.
57     # FIXME: this is how browsers currently work, but the spec should clarify if this is the
58     #        expected behavior, see https://github.com/w3c/webdriver/issues/1153.
59     assert session.alert.text == "Bye"
60     session.alert.dismiss()