Update web-platform-tests to revision c2b30ef30749b6a8f2cc832761dfe011e63d5e94

This commit is contained in:
WPT Sync Bot 2018-10-05 21:34:34 -04:00
parent 987e376ca7
commit eda9b9b73a
142 changed files with 3513 additions and 851 deletions

View file

@ -0,0 +1,137 @@
# META: timeout=long
import pytest
from webdriver.error import NoSuchCookieException
from tests.support.asserts import assert_dialog_handled, assert_error, assert_success
def add_cookie(session, cookie):
return session.transport.send(
"POST", "session/{session_id}/cookie".format(**vars(session)),
{"cookie": cookie})
@pytest.fixture
def check_user_prompt_closed_without_exception(session, url, create_dialog):
def check_user_prompt_closed_without_exception(dialog_type, retval):
new_cookie = {
"name": "foo",
"value": "bar",
}
session.url = url("/common/blank.html")
create_dialog(dialog_type, text=dialog_type)
response = add_cookie(session, new_cookie)
assert_success(response)
assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
assert session.cookies("foo")
return check_user_prompt_closed_without_exception
@pytest.fixture
def check_user_prompt_closed_with_exception(session, url, create_dialog):
def check_user_prompt_closed_with_exception(dialog_type, retval):
new_cookie = {
"name": "foo",
"value": "bar",
}
session.url = url("/common/blank.html")
create_dialog(dialog_type, text=dialog_type)
response = add_cookie(session, new_cookie)
assert_error(response, "unexpected alert open")
assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
with pytest.raises(NoSuchCookieException):
assert session.cookies("foo")
return check_user_prompt_closed_with_exception
@pytest.fixture
def check_user_prompt_not_closed_but_exception(session, url, create_dialog):
def check_user_prompt_not_closed_but_exception(dialog_type):
new_cookie = {
"name": "foo",
"value": "bar",
}
session.url = url("/common/blank.html")
create_dialog(dialog_type, text=dialog_type)
response = add_cookie(session, new_cookie)
assert_error(response, "unexpected alert open")
assert session.alert.text == dialog_type
session.alert.dismiss()
with pytest.raises(NoSuchCookieException):
assert session.cookies("foo")
return check_user_prompt_not_closed_but_exception
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", True),
("prompt", ""),
])
def test_accept(check_user_prompt_closed_without_exception, dialog_type, retval):
check_user_prompt_closed_without_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept and notify"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", True),
("prompt", ""),
])
def test_accept_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_dismiss(check_user_prompt_closed_without_exception, dialog_type, retval):
check_user_prompt_closed_without_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss and notify"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_dismiss_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "ignore"})
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_ignore(check_user_prompt_not_closed_but_exception, dialog_type):
check_user_prompt_not_closed_but_exception(dialog_type)
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_default(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)

View file

@ -0,0 +1,119 @@
# META: timeout=long
import pytest
from webdriver.error import NoSuchCookieException
from tests.support.asserts import assert_dialog_handled, assert_error, assert_success
def delete_all_cookies(session):
return session.transport.send(
"DELETE", "/session/{session_id}/cookie".format(**vars(session)))
@pytest.fixture
def check_user_prompt_closed_without_exception(session, create_dialog, create_cookie):
def check_user_prompt_closed_without_exception(dialog_type, retval):
create_cookie("foo", value="bar", path="/common/blank.html")
create_dialog(dialog_type, text=dialog_type)
response = delete_all_cookies(session)
assert_success(response)
assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
assert session.cookies() == []
return check_user_prompt_closed_without_exception
@pytest.fixture
def check_user_prompt_closed_with_exception(session, create_dialog, create_cookie):
def check_user_prompt_closed_with_exception(dialog_type, retval):
create_cookie("foo", value="bar", path="/common/blank.html")
create_dialog(dialog_type, text=dialog_type)
response = delete_all_cookies(session)
assert_error(response, "unexpected alert open")
assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
assert session.cookies() != []
return check_user_prompt_closed_with_exception
@pytest.fixture
def check_user_prompt_not_closed_but_exception(session, create_dialog, create_cookie):
def check_user_prompt_not_closed_but_exception(dialog_type):
create_cookie("foo", value="bar", path="/common/blank.html")
create_dialog(dialog_type, text=dialog_type)
response = delete_all_cookies(session)
assert_error(response, "unexpected alert open")
assert session.alert.text == dialog_type
session.alert.dismiss()
assert session.cookies() != []
return check_user_prompt_not_closed_but_exception
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", True),
("prompt", ""),
])
def test_accept(check_user_prompt_closed_without_exception, dialog_type, retval):
check_user_prompt_closed_without_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept and notify"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", True),
("prompt", ""),
])
def test_accept_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_dismiss(check_user_prompt_closed_without_exception, dialog_type, retval):
check_user_prompt_closed_without_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss and notify"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_dismiss_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "ignore"})
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_ignore(check_user_prompt_not_closed_but_exception, dialog_type):
check_user_prompt_not_closed_but_exception(dialog_type)
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_default(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)

View file

@ -0,0 +1,132 @@
# META: timeout=long
import pytest
from tests.support.asserts import assert_dialog_handled, assert_error, assert_success
from tests.support.inline import inline
def element_clear(session, element):
return session.transport.send(
"POST", "/session/{session_id}/element/{element_id}/clear".format(
session_id=session.session_id,
element_id=element.id))
@pytest.fixture
def check_user_prompt_closed_without_exception(session, create_dialog):
def check_user_prompt_closed_without_exception(dialog_type, retval):
session.url = inline("<input type=text>")
element = session.find.css("input", all=False)
element.send_keys("foo")
assert element.property("value") == "foo"
create_dialog(dialog_type, text=dialog_type)
response = element_clear(session, element)
assert_success(response)
assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
assert element.property("value") == ""
return check_user_prompt_closed_without_exception
@pytest.fixture
def check_user_prompt_closed_with_exception(session, create_dialog):
def check_user_prompt_closed_with_exception(dialog_type, retval):
session.url = inline("<input type=text>")
element = session.find.css("input", all=False)
element.send_keys("foo")
assert element.property("value") == "foo"
create_dialog(dialog_type, text=dialog_type)
response = element_clear(session, element)
assert_error(response, "unexpected alert open")
assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
assert element.property("value") == "foo"
return check_user_prompt_closed_with_exception
@pytest.fixture
def check_user_prompt_not_closed_but_exception(session, create_dialog):
def check_user_prompt_not_closed_but_exception(dialog_type):
session.url = inline("<input type=text>")
element = session.find.css("input", all=False)
element.send_keys("foo")
assert element.property("value") == "foo"
create_dialog(dialog_type, text=dialog_type)
response = element_clear(session, element)
assert_error(response, "unexpected alert open")
assert session.alert.text == dialog_type
session.alert.dismiss()
assert element.property("value") == "foo"
return check_user_prompt_not_closed_but_exception
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", True),
("prompt", ""),
])
def test_accept(check_user_prompt_closed_without_exception, dialog_type, retval):
check_user_prompt_closed_without_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept and notify"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", True),
("prompt", ""),
])
def test_accept_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_dismiss(check_user_prompt_closed_without_exception, dialog_type, retval):
check_user_prompt_closed_without_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss and notify"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_dismiss_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "ignore"})
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_ignore(check_user_prompt_not_closed_but_exception, dialog_type):
check_user_prompt_not_closed_but_exception(dialog_type)
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_default(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)

View file

@ -0,0 +1,123 @@
# META: timeout=long
import pytest
from tests.support.asserts import assert_dialog_handled, assert_error, assert_success
from tests.support.inline import inline
def element_click(session, element):
return session.transport.send(
"POST", "session/{session_id}/element/{element_id}/click".format(
session_id=session.session_id,
element_id=element.id))
@pytest.fixture
def check_user_prompt_closed_without_exception(session, create_dialog):
def check_user_prompt_closed_without_exception(dialog_type, retval):
session.url = inline("<input type=text>")
element = session.find.css("input", all=False)
create_dialog(dialog_type, text=dialog_type)
response = element_click(session, element)
assert_success(response)
assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
assert session.active_element == element
return check_user_prompt_closed_without_exception
@pytest.fixture
def check_user_prompt_closed_with_exception(session, create_dialog):
def check_user_prompt_closed_with_exception(dialog_type, retval):
session.url = inline("<input type=text>")
element = session.find.css("input", all=False)
create_dialog(dialog_type, text=dialog_type)
response = element_click(session, element)
assert_error(response, "unexpected alert open")
assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
assert session.active_element != element
return check_user_prompt_closed_with_exception
@pytest.fixture
def check_user_prompt_not_closed_but_exception(session, create_dialog):
def check_user_prompt_not_closed_but_exception(dialog_type):
session.url = inline("<input type=text>")
element = session.find.css("input", all=False)
create_dialog(dialog_type, text=dialog_type)
response = element_click(session, element)
assert_error(response, "unexpected alert open")
assert session.alert.text == dialog_type
session.alert.dismiss()
assert session.active_element != element
return check_user_prompt_not_closed_but_exception
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", True),
("prompt", ""),
])
def test_accept(check_user_prompt_closed_without_exception, dialog_type, retval):
check_user_prompt_closed_without_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept and notify"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", True),
("prompt", ""),
])
def test_accept_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_dismiss(check_user_prompt_closed_without_exception, dialog_type, retval):
check_user_prompt_closed_without_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss and notify"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_dismiss_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "ignore"})
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_ignore(check_user_prompt_not_closed_but_exception, dialog_type):
check_user_prompt_not_closed_but_exception(dialog_type)
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_default(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)

View file

@ -1,4 +1,4 @@
from tests.support.asserts import assert_error, assert_same_element
from tests.support.asserts import assert_error, assert_is_active_element, assert_success
from tests.support.inline import inline
@ -11,37 +11,12 @@ def get_active_element(session):
"GET", "session/{session_id}/element/active".format(**vars(session)))
def assert_is_active_element(session, response):
"""Ensure that the provided object is a successful WebDriver
response describing an element reference and that the referenced
element matches the element returned by the `activeElement`
attribute of the current browsing context's active document.
"""
assert response.status == 200
assert "value" in response.body
from_js = session.execute_script("return document.activeElement")
if response.body["value"] is None:
assert from_js is None
else:
assert_same_element(session, response.body["value"], from_js)
def test_no_browsing_context(session, closed_window):
response = get_active_element(session)
assert_error(response, "no such window")
def test_success_document(session):
"""
> [...]
> 3. Let active element be the active element of the current browsing
> context's document element.
> 4. Let active web element be the JSON Serialization of active element.
> 5. Return success with data active web element.
"""
session.url = inline("""
<body>
<h1>Heading</h1>
@ -50,8 +25,10 @@ def test_success_document(session):
<input style="opacity: 0" />
<p>Another element</p>
</body>""")
response = get_active_element(session)
assert_is_active_element(session, response)
element = assert_success(response)
assert_is_active_element(session, element)
def test_sucess_input(session):
@ -62,8 +39,10 @@ def test_sucess_input(session):
<input style="opacity: 0" />
<p>Another element</p>
</body>""")
response = get_active_element(session)
assert_is_active_element(session, response)
element = assert_success(response)
assert_is_active_element(session, element)
def test_sucess_input_non_interactable(session):
@ -74,8 +53,10 @@ def test_sucess_input_non_interactable(session):
<input style="opacity: 0" autofocus />
<p>Another element</p>
</body>""")
response = get_active_element(session)
assert_is_active_element(session, response)
element = assert_success(response)
assert_is_active_element(session, element)
def test_success_explicit_focus(session):
@ -88,15 +69,18 @@ def test_success_explicit_focus(session):
session.execute_script("document.body.getElementsByTagName('h1')[0].focus()")
response = get_active_element(session)
assert_is_active_element(session, response)
element = assert_success(response)
assert_is_active_element(session, element)
session.execute_script("document.body.getElementsByTagName('input')[0].focus()")
response = get_active_element(session)
assert_is_active_element(session, response)
element = assert_success(response)
assert_is_active_element(session, element)
session.execute_script("document.body.getElementsByTagName('iframe')[0].focus()")
response = get_active_element(session)
assert_is_active_element(session, response)
element = assert_success(response)
assert_is_active_element(session, element)
session.execute_script("document.body.getElementsByTagName('iframe')[0].focus();")
session.execute_script("""
@ -107,11 +91,13 @@ def test_success_explicit_focus(session):
iframe.removeNode(true);
}""")
response = get_active_element(session)
assert_is_active_element(session, response)
element = assert_success(response)
assert_is_active_element(session, element)
session.execute_script("document.body.appendChild(document.createElement('textarea'))")
response = get_active_element(session)
assert_is_active_element(session, response)
element = assert_success(response)
assert_is_active_element(session, element)
def test_success_iframe_content(session):
@ -125,7 +111,8 @@ def test_success_iframe_content(session):
""")
response = get_active_element(session)
assert_is_active_element(session, response)
element = assert_success(response)
assert_is_active_element(session, element)
def test_missing_document_element(session):

View file

@ -0,0 +1,119 @@
# META: timeout=long
import pytest
from tests.support.asserts import (
assert_dialog_handled,
assert_error,
assert_is_active_element,
assert_success
)
from tests.support.inline import inline
def get_active_element(session):
return session.transport.send(
"GET", "session/{session_id}/element/active".format(**vars(session)))
@pytest.fixture
def check_user_prompt_closed_without_exception(session, create_dialog):
def check_user_prompt_closed_without_exception(dialog_type, retval):
session.url = inline("<input type=text>")
create_dialog(dialog_type, text=dialog_type)
response = get_active_element(session)
element = assert_success(response)
assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
assert_is_active_element(session, element)
return check_user_prompt_closed_without_exception
@pytest.fixture
def check_user_prompt_closed_with_exception(session, create_dialog):
def check_user_prompt_closed_with_exception(dialog_type, retval):
session.url = inline("<input type=text>")
create_dialog(dialog_type, text=dialog_type)
response = get_active_element(session)
assert_error(response, "unexpected alert open")
assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
return check_user_prompt_closed_with_exception
@pytest.fixture
def check_user_prompt_not_closed_but_exception(session, create_dialog):
def check_user_prompt_not_closed_but_exception(dialog_type):
session.url = inline("<input type=text>")
create_dialog(dialog_type, text=dialog_type)
response = get_active_element(session)
assert_error(response, "unexpected alert open")
assert session.alert.text == dialog_type
session.alert.dismiss()
return check_user_prompt_not_closed_but_exception
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", True),
("prompt", ""),
])
def test_accept(check_user_prompt_closed_without_exception, dialog_type, retval):
check_user_prompt_closed_without_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept and notify"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", True),
("prompt", ""),
])
def test_accept_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_dismiss(check_user_prompt_closed_without_exception, dialog_type, retval):
check_user_prompt_closed_without_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss and notify"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_dismiss_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "ignore"})
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_ignore(check_user_prompt_not_closed_but_exception, dialog_type):
check_user_prompt_not_closed_but_exception(dialog_type)
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_default(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)

View file

@ -0,0 +1,118 @@
# META: timeout=long
import pytest
from tests.support.asserts import assert_error, assert_success, assert_dialog_handled
from tests.support.inline import inline
def get_element_attribute(session, element, attr):
return session.transport.send(
"GET", "session/{session_id}/element/{element_id}/attribute/{attr}".format(
session_id=session.session_id,
element_id=element,
attr=attr))
@pytest.fixture
def check_user_prompt_closed_without_exception(session, create_dialog):
def check_user_prompt_closed_without_exception(dialog_type, retval):
session.url = inline("<input id=foo>")
element = session.find.css("#foo", all=False)
create_dialog(dialog_type, text=dialog_type)
response = get_element_attribute(session, element.id, "id")
assert_success(response, "foo")
assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
return check_user_prompt_closed_without_exception
@pytest.fixture
def check_user_prompt_closed_with_exception(session, create_dialog):
def check_user_prompt_closed_with_exception(dialog_type, retval):
session.url = inline("<input id=foo>")
element = session.find.css("#foo", all=False)
create_dialog(dialog_type, text=dialog_type)
response = get_element_attribute(session, element.id, "id")
assert_error(response, "unexpected alert open")
assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
return check_user_prompt_closed_with_exception
@pytest.fixture
def check_user_prompt_not_closed_but_exception(session, create_dialog):
def check_user_prompt_not_closed_but_exception(dialog_type):
session.url = inline("<input id=foo>")
element = session.find.css("#foo", all=False)
create_dialog(dialog_type, text=dialog_type)
response = get_element_attribute(session, element.id, "id")
assert_error(response, "unexpected alert open")
assert session.alert.text == dialog_type
session.alert.dismiss()
return check_user_prompt_not_closed_but_exception
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", True),
("prompt", ""),
])
def test_accept(check_user_prompt_closed_without_exception, dialog_type, retval):
check_user_prompt_closed_without_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept and notify"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", True),
("prompt", ""),
])
def test_accept_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_dismiss(check_user_prompt_closed_without_exception, dialog_type, retval):
check_user_prompt_closed_without_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss and notify"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_dismiss_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "ignore"})
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_ignore(check_user_prompt_not_closed_but_exception, dialog_type):
check_user_prompt_not_closed_but_exception(dialog_type)
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_default(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)

View file

@ -0,0 +1,117 @@
# META: timeout=long
import pytest
from tests.support.asserts import assert_error, assert_success, assert_dialog_handled
from tests.support.inline import inline
def get_element_text(session, element_id):
return session.transport.send(
"GET", "session/{session_id}/element/{element_id}/text".format(
session_id=session.session_id,
element_id=element_id))
@pytest.fixture
def check_user_prompt_closed_without_exception(session, create_dialog):
def check_user_prompt_closed_without_exception(dialog_type, retval):
session.url = inline("<p id=foo>bar</p>")
element = session.find.css("#foo", all=False)
create_dialog(dialog_type, text=dialog_type)
response = get_element_text(session, element.id)
assert_success(response, "bar")
assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
return check_user_prompt_closed_without_exception
@pytest.fixture
def check_user_prompt_closed_with_exception(session, create_dialog):
def check_user_prompt_closed_with_exception(dialog_type, retval):
session.url = inline("<p id=foo>bar</p>")
element = session.find.css("#foo", all=False)
create_dialog(dialog_type, text=dialog_type)
response = get_element_text(session, element.id)
assert_error(response, "unexpected alert open")
assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
return check_user_prompt_closed_with_exception
@pytest.fixture
def check_user_prompt_not_closed_but_exception(session, create_dialog):
def check_user_prompt_not_closed_but_exception(dialog_type):
session.url = inline("<p id=foo>bar</p>")
element = session.find.css("#foo", all=False)
create_dialog(dialog_type, text=dialog_type)
response = get_element_text(session, element.id)
assert_error(response, "unexpected alert open")
assert session.alert.text == dialog_type
session.alert.dismiss()
return check_user_prompt_not_closed_but_exception
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", True),
("prompt", ""),
])
def test_accept(check_user_prompt_closed_without_exception, dialog_type, retval):
check_user_prompt_closed_without_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept and notify"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", True),
("prompt", ""),
])
def test_accept_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_dismiss(check_user_prompt_closed_without_exception, dialog_type, retval):
check_user_prompt_closed_without_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss and notify"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_dismiss_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "ignore"})
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_ignore(check_user_prompt_not_closed_but_exception, dialog_type):
check_user_prompt_not_closed_but_exception(dialog_type)
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_default(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)

View file

@ -0,0 +1,118 @@
# META: timeout=long
import pytest
from webdriver.error import NoSuchCookieException
from tests.support.asserts import assert_dialog_handled, assert_error, assert_success
def get_named_cookie(session, name):
return session.transport.send(
"GET", "session/{session_id}/cookie/{name}".format(
session_id=session.session_id,
name=name))
@pytest.fixture
def check_user_prompt_closed_without_exception(session, create_dialog, create_cookie):
def check_user_prompt_closed_without_exception(dialog_type, retval):
create_cookie("foo", value="bar", path="/common/blank.html")
create_dialog(dialog_type, text=dialog_type)
response = get_named_cookie(session, "foo")
cookie = assert_success(response)
assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
assert cookie["name"] == "foo"
assert cookie["value"] == "bar"
return check_user_prompt_closed_without_exception
@pytest.fixture
def check_user_prompt_closed_with_exception(session, create_dialog, create_cookie):
def check_user_prompt_closed_with_exception(dialog_type, retval):
create_cookie("foo", value="bar", path="/common/blank.html")
create_dialog(dialog_type, text=dialog_type)
response = get_named_cookie(session, "foo")
assert_error(response, "unexpected alert open")
assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
return check_user_prompt_closed_with_exception
@pytest.fixture
def check_user_prompt_not_closed_but_exception(session, create_dialog, create_cookie):
def check_user_prompt_not_closed_but_exception(dialog_type):
create_cookie("foo", value="bar", path="/common/blank.html")
create_dialog(dialog_type, text=dialog_type)
response = get_named_cookie(session, "foo")
assert_error(response, "unexpected alert open")
assert session.alert.text == dialog_type
session.alert.dismiss()
return check_user_prompt_not_closed_but_exception
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", True),
("prompt", ""),
])
def test_accept(check_user_prompt_closed_without_exception, dialog_type, retval):
check_user_prompt_closed_without_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept and notify"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", True),
("prompt", ""),
])
def test_accept_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_dismiss(check_user_prompt_closed_without_exception, dialog_type, retval):
check_user_prompt_closed_without_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss and notify"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_dismiss_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "ignore"})
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_ignore(check_user_prompt_not_closed_but_exception, dialog_type):
check_user_prompt_not_closed_but_exception(dialog_type)
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_default(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)

View file

@ -0,0 +1,113 @@
# META: timeout=long
import pytest
from tests.support.asserts import assert_error, assert_success, assert_dialog_handled
from tests.support.inline import inline
def get_page_source(session):
return session.transport.send(
"GET", "session/{session_id}/source".format(**vars(session)))
@pytest.fixture
def check_user_prompt_closed_without_exception(session, create_dialog):
def check_user_prompt_closed_without_exception(dialog_type, retval):
session.url = inline("<div/>")
expected = session.execute_script("return document.documentElement.outerHTML")
create_dialog(dialog_type, text=dialog_type)
response = get_page_source(session)
assert_success(response, expected)
assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
return check_user_prompt_closed_without_exception
@pytest.fixture
def check_user_prompt_closed_with_exception(session, create_dialog):
def check_user_prompt_closed_with_exception(dialog_type, retval):
session.url = inline("<div/>")
create_dialog(dialog_type, text=dialog_type)
response = get_page_source(session)
assert_error(response, "unexpected alert open")
assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
return check_user_prompt_closed_with_exception
@pytest.fixture
def check_user_prompt_not_closed_but_exception(session, create_dialog):
def check_user_prompt_not_closed_but_exception(dialog_type):
session.url = inline("<div/>")
create_dialog(dialog_type, text=dialog_type)
response = get_page_source(session)
assert_error(response, "unexpected alert open")
assert session.alert.text == dialog_type
session.alert.dismiss()
return check_user_prompt_not_closed_but_exception
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", True),
("prompt", ""),
])
def test_accept(check_user_prompt_closed_without_exception, dialog_type, retval):
check_user_prompt_closed_without_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept and notify"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", True),
("prompt", ""),
])
def test_accept_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_dismiss(check_user_prompt_closed_without_exception, dialog_type, retval):
check_user_prompt_closed_without_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss and notify"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_dismiss_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "ignore"})
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_ignore(check_user_prompt_not_closed_but_exception, dialog_type):
check_user_prompt_not_closed_but_exception(dialog_type)
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_default(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)

View file

@ -0,0 +1,113 @@
# META: timeout=long
import pytest
from tests.support.asserts import assert_error, assert_success, assert_dialog_handled
from tests.support.inline import inline
def navigate_to(session, url):
return session.transport.send(
"POST", "session/{session_id}/url".format(**vars(session)),
{"url": url})
@pytest.fixture
def check_user_prompt_closed_without_exception(session, create_dialog):
def check_user_prompt_closed_without_exception(dialog_type, retval):
url = inline("<div/>")
create_dialog(dialog_type, text=dialog_type)
response = navigate_to(session, url)
assert_success(response)
assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
assert session.url == url
return check_user_prompt_closed_without_exception
@pytest.fixture
def check_user_prompt_closed_with_exception(session, create_dialog):
def check_user_prompt_closed_with_exception(dialog_type, retval):
url = inline("<div/>")
create_dialog(dialog_type, text=dialog_type)
response = navigate_to(session, url)
assert_error(response, "unexpected alert open")
assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
assert session.url != url
return check_user_prompt_closed_with_exception
@pytest.fixture
def check_user_prompt_not_closed_but_exception(session, create_dialog):
def check_user_prompt_not_closed_but_exception(dialog_type):
url = inline("<div/>")
create_dialog(dialog_type, text=dialog_type)
response = navigate_to(session, url)
assert_error(response, "unexpected alert open")
assert session.alert.text == dialog_type
session.alert.dismiss()
assert session.url != url
return check_user_prompt_not_closed_but_exception
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept"})
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_accept(check_user_prompt_closed_without_exception, dialog_type):
# retval not testable for confirm and prompt because window is gone
check_user_prompt_closed_without_exception(dialog_type, None)
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept and notify"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", True),
("prompt", ""),
])
def test_accept_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss"})
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_dismiss(check_user_prompt_closed_without_exception, dialog_type):
# retval not testable for confirm and prompt because window is gone
check_user_prompt_closed_without_exception(dialog_type, None)
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss and notify"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_dismiss_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "ignore"})
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_ignore(check_user_prompt_not_closed_but_exception, dialog_type):
check_user_prompt_not_closed_but_exception(dialog_type)
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_default(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)

View file

@ -0,0 +1,124 @@
# META: timeout=long
import pytest
from tests.perform_actions.support.refine import get_keys
from tests.support.asserts import assert_error, assert_success, assert_dialog_handled
actions = [{
"type": "key",
"id": "foobar",
"actions": [
{"type": "keyDown", "value": "a"},
{"type": "keyUp", "value": "a"},
]
}]
def perform_actions(session, actions):
return session.transport.send(
"POST",
"/session/{session_id}/actions".format(session_id=session.session_id),
{"actions": actions})
@pytest.fixture
def check_user_prompt_closed_without_exception(session, create_dialog, key_chain, key_reporter):
def check_user_prompt_closed_without_exception(dialog_type, retval):
create_dialog(dialog_type, text=dialog_type)
response = perform_actions(session, actions)
assert_success(response)
assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
assert get_keys(key_reporter) == "a"
return check_user_prompt_closed_without_exception
@pytest.fixture
def check_user_prompt_closed_with_exception(session, create_dialog, key_chain, key_reporter):
def check_user_prompt_closed_with_exception(dialog_type, retval):
create_dialog(dialog_type, text=dialog_type)
response = perform_actions(session, actions)
assert_error(response, "unexpected alert open")
assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
assert get_keys(key_reporter) == ""
return check_user_prompt_closed_with_exception
@pytest.fixture
def check_user_prompt_not_closed_but_exception(session, create_dialog, key_reporter):
def check_user_prompt_not_closed_but_exception(dialog_type):
create_dialog(dialog_type, text=dialog_type)
response = perform_actions(session, actions)
assert_error(response, "unexpected alert open")
assert session.alert.text == dialog_type
session.alert.dismiss()
assert get_keys(key_reporter) == ""
return check_user_prompt_not_closed_but_exception
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", True),
("prompt", ""),
])
def test_accept(check_user_prompt_closed_without_exception, dialog_type, retval):
check_user_prompt_closed_without_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept and notify"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", True),
("prompt", ""),
])
def test_accept_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_dismiss(check_user_prompt_closed_without_exception, dialog_type, retval):
check_user_prompt_closed_without_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss and notify"})
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_dismiss_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)
@pytest.mark.capabilities({"unhandledPromptBehavior": "ignore"})
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_ignore(check_user_prompt_not_closed_but_exception, dialog_type):
check_user_prompt_not_closed_but_exception(dialog_type)
@pytest.mark.parametrize("dialog_type, retval", [
("alert", None),
("confirm", False),
("prompt", None),
])
def test_default(check_user_prompt_closed_with_exception, dialog_type, retval):
check_user_prompt_closed_with_exception(dialog_type, retval)

View file

@ -115,6 +115,16 @@ def assert_files_uploaded(session, element, files):
assert get_file_contents(index) == f.read()
def assert_is_active_element(session, element):
"""Verify that element reference is the active element."""
from_js = session.execute_script("return document.activeElement")
if element is None:
assert from_js is None
else:
assert_same_element(session, element, from_js)
def assert_same_element(session, a, b):
"""Verify that two element references describe the same element."""
if isinstance(a, dict):