testing/web-platform/tests/webdriver/tests/accept_alert/accept.py
author Henrik Skupin <mail@hskupin.info>
Tue, 24 Apr 2018 18:57:48 +0200
changeset 792546 91ef9aae32eb1e07de7c9dd7d8f51de0080e5ccc
parent 792391 a41eba4d76259bd54fec7d9b420beb4173dd9660
child 796318 66309dd35c520016de7cf3d1b00368b9a6fa3653
permissions -rw-r--r--
Bug 1455568 - [wdspec] Use shared command function for each WebDriver command. Tests for a specific command have to use a shared function for each of the included tests of a module to avoid redefinition of the same code. In a follow-up patch those shared methods could even be separated out as fixtures for each of the sub folders. MozReview-Commit-ID: 11lAp7J8IoZ

from tests.support.asserts import assert_error, assert_success
from tests.support.inline import inline


def accept_alert(session):
    return session.transport.send(
        "POST", "session/{session_id}/alert/accept".format(**vars(session)))


# 18.2 Accept Alert

def test_no_browsing_context(session, create_window):
    # 18.2 step 1
    session.window_handle = create_window()
    session.close()

    response = accept_alert(session)
    assert_error(response, "no such window")


def test_no_user_prompt(session):
    # 18.2 step 2
    response = accept_alert(session)
    assert_error(response, "no such alert")


def test_accept_alert(session):
    # 18.2 step 3
    session.url = inline("<script>window.alert('Hello');</script>")
    response = accept_alert(session)
    assert_success(response)


def test_accept_confirm(session):
    # 18.2 step 3
    session.url = inline("<script>window.result = window.confirm('Hello');</script>")
    response = accept_alert(session)
    assert_success(response)
    assert session.execute_script("return window.result") is True


def test_accept_prompt(session):
    # 18.2 step 3
    session.url = inline("<script>window.result = window.prompt('Enter Your Name: ', 'Federer');</script>")
    response = accept_alert(session)
    assert_success(response)
    assert session.execute_script("return window.result") == "Federer"