aboutsummaryrefslogtreecommitdiffstats
path: root/tests/wpt/web-platform-tests/webdriver/tests/execute_script/user_prompts.py
blob: 8d91bdd8f9f122026b7f58125806961513b1ac7b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import pytest

from webdriver import error


# 15.2 Executing Script

def test_handle_prompt_accept(new_session, add_browser_capabilites):
    _, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "accept"})}})
    session.execute_script("window.alert('Hello');")
    with pytest.raises(error.NoSuchAlertException):
        session.alert.accept()


def test_handle_prompt_dismiss(new_session, add_browser_capabilites):
    _, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "dismiss"})}})
    session.execute_script("window.alert('Hello');")
    with pytest.raises(error.NoSuchAlertException):
        session.alert.dismiss()


def test_handle_prompt_dismiss_and_notify(new_session, add_browser_capabilites):
    _, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "dismiss and notify"})}})
    with pytest.raises(error.UnexpectedAlertOpenException):
        session.execute_script("window.alert('Hello');")
    with pytest.raises(error.NoSuchAlertException):
        session.alert.dismiss()


def test_handle_prompt_accept_and_notify(new_session, add_browser_capabilites):
    _, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "accept and notify"})}})
    with pytest.raises(error.UnexpectedAlertOpenException):
        session.execute_script("window.alert('Hello');")
    with pytest.raises(error.NoSuchAlertException):
        session.alert.accept()


def test_handle_prompt_ignore(new_session, add_browser_capabilites):
    _, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "ignore"})}})
    with pytest.raises(error.UnexpectedAlertOpenException):
        session.execute_script("window.alert('Hello');")
    session.alert.dismiss()


def test_handle_prompt_default(new_session, add_browser_capabilites):
    _, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({})}})
    with pytest.raises(error.UnexpectedAlertOpenException):
        session.execute_script("window.alert('Hello');")
    with pytest.raises(error.NoSuchAlertException):
        session.alert.dismiss()


def test_handle_prompt_twice(new_session, add_browser_capabilites):
    _, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "accept"})}})
    session.execute_script("window.alert('Hello');window.alert('Bye');")
    # The first alert has been accepted by the user prompt handler, the second one remains.
    # FIXME: this is how browsers currently work, but the spec should clarify if this is the
    #        expected behavior, see https://github.com/w3c/webdriver/issues/1153.
    assert session.alert.text == "Bye"
    session.alert.dismiss()