Update web-platform-tests to revision 2b7dace05fc1869398ee24f84fda4c0e4c0455ae

This commit is contained in:
WPT Sync Bot 2018-08-31 21:37:12 +00:00 committed by Tom Servo
parent b23125d590
commit 6c901de216
844 changed files with 19802 additions and 3093 deletions

View file

@ -27,6 +27,11 @@ def test_no_browsing_context(session, closed_window):
assert_error(response, "no such window")
def test_ending_comment(session):
response = execute_script(session, "return 1; // foo")
assert_success(response, 1)
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_abort_by_user_prompt(session, dialog_type):
response = execute_script(

View file

@ -0,0 +1,48 @@
from tests.support.asserts import assert_error, assert_success
from tests.support.inline import inline
def get_element_css_value(session, element_id, prop):
return session.transport.send(
"GET",
"session/{session_id}/element/{element_id}/css/{prop}".format(
session_id=session.session_id,
element_id=element_id,
prop=prop
)
)
def test_no_browsing_context(session, closed_window):
response = get_element_css_value(session, "foo", "bar")
assert_error(response, "no such window")
def test_element_not_found(session):
result = get_element_css_value(session, "foo", "display")
assert_error(result, "no such element")
def test_element_stale(session):
session.url = inline("<input>")
element = session.find.css("input", all=False)
session.refresh()
result = get_element_css_value(session, element.id, "display")
assert_error(result, "stale element reference")
def test_property_name_value(session):
session.url = inline("""<input style="display: block">""")
element = session.find.css("input", all=False)
result = get_element_css_value(session, element.id, "display")
assert_success(result, "block")
def test_property_name_not_existent(session):
session.url = inline("<input>")
element = session.find.css("input", all=False)
result = get_element_css_value(session, element.id, "foo")
assert_success(result, "")

View file

@ -0,0 +1,121 @@
# 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_css_value(session, element_id, prop):
return session.transport.send(
"GET",
"session/{session_id}/element/{element_id}/css/{prop}".format(
session_id=session.session_id,
element_id=element_id,
prop=prop
)
)
@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 style="display: block">""")
element = session.find.css("input", all=False)
create_dialog(dialog_type, text=dialog_type)
response = get_element_css_value(session, element.id, "display")
assert_success(response, "block")
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 style="display: block">""")
element = session.find.css("input", all=False)
create_dialog(dialog_type, text=dialog_type)
response = get_element_css_value(session, element.id, "display")
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 style="display: block">""")
element = session.find.css("input", all=False)
create_dialog(dialog_type, text=dialog_type)
response = get_element_css_value(session, element.id, "display")
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,10 @@
def retrieve_element_rect(session, element):
return session.execute_script("""
let rect = arguments[0].getBoundingClientRect();
return {
x: rect.left + window.pageXOffset,
y: rect.top + window.pageYOffset,
width: rect.width,
height: rect.height,
};
""", args=(element,))

View file

@ -0,0 +1,41 @@
from tests.support.asserts import assert_error, assert_success
from tests.support.inline import inline
from . import retrieve_element_rect
def get_element_rect(session, element_id):
return session.transport.send(
"GET",
"session/{session_id}/element/{element_id}/rect".format(
session_id=session.session_id,
element_id=element_id,
)
)
def test_no_browsing_context(session, closed_window):
response = get_element_rect(session, "foo")
assert_error(response, "no such window")
def test_element_not_found(session):
result = get_element_rect(session, "foo")
assert_error(result, "no such element")
def test_element_stale(session):
session.url = inline("<input>")
element = session.find.css("input", all=False)
session.refresh()
result = get_element_rect(session, element.id)
assert_error(result, "stale element reference")
def test_basic(session):
session.url = inline("<input>")
element = session.find.css("input", all=False)
result = get_element_rect(session, element.id)
assert_success(result, retrieve_element_rect(session, element))

View file

@ -0,0 +1,122 @@
# META: timeout=long
import pytest
from tests.support.asserts import assert_error, assert_success, assert_dialog_handled
from tests.support.inline import inline
from . import retrieve_element_rect
def get_element_rect(session, element_id):
return session.transport.send(
"GET",
"session/{session_id}/element/{element_id}/rect".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>")
element = session.find.css("input", all=False)
create_dialog(dialog_type, text=dialog_type)
response = get_element_rect(session, element.id)
assert_success(response, retrieve_element_rect(session, element))
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>")
element = session.find.css("input", all=False)
create_dialog(dialog_type, text=dialog_type)
response = get_element_rect(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("<input>")
element = session.find.css("input", all=False)
create_dialog(dialog_type, text=dialog_type)
response = get_element_rect(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,109 @@
import pytest
from tests.support.asserts import assert_error, assert_success
from tests.support.inline import inline
def is_element_enabled(session, element_id):
return session.transport.send(
"GET",
"session/{session_id}/element/{element_id}/enabled".format(
session_id=session.session_id,
element_id=element_id
)
)
def test_no_browsing_context(session, closed_window):
response = is_element_enabled(session, "foo")
assert_error(response, "no such window")
def test_element_stale(session):
session.url = inline("<input>")
element = session.find.css("input", all=False)
session.refresh()
result = is_element_enabled(session, element.id)
assert_error(result, "stale element reference")
@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"])
def test_form_control_disabled(session, element):
session.url = inline("<{} disabled/>".format(element))
element = session.find.css(element, all=False)
result = is_element_enabled(session, element.id)
assert_success(result, False)
@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"])
def test_form_control_enabled(session, element):
session.url = inline("<{}/>".format(element))
element = session.find.css(element, all=False)
result = is_element_enabled(session, element.id)
assert_success(result, True)
@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"])
def test_fieldset_disabled_descendant(session, element):
session.url = inline("<fieldset disabled><{}/></fieldset>".format(element))
element = session.find.css(element, all=False)
result = is_element_enabled(session, element.id)
assert_success(result, False)
@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"])
def test_fieldset_enabled_descendant(session, element):
session.url = inline("<fieldset><{}/></fieldset>".format(element))
element = session.find.css(element, all=False)
result = is_element_enabled(session, element.id)
assert_success(result, True)
@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"])
def test_fieldset_disabled_descendant_legend(session, element):
session.url = inline("<fieldset disabled><legend><{}/></legend></fieldset>".format(element))
element = session.find.css(element, all=False)
result = is_element_enabled(session, element.id)
assert_success(result, True)
@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"])
def test_fieldset_enabled_descendant_legend(session, element):
session.url = inline("<fieldset><legend><{}/></legend></fieldset>".format(element))
element = session.find.css(element, all=False)
result = is_element_enabled(session, element.id)
assert_success(result, True)
@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"])
def test_xhtml_form_control_disabled(session, element):
session.url = inline("""<{} disabled="disabled"/>""".format(element),
doctype="xhtml")
element = session.find.css(element, all=False)
result = is_element_enabled(session, element.id)
assert_success(result, False)
@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"])
def test_xhtml_form_control_enabled(session, element):
session.url = inline("""<{}/>""".format(element), doctype="xhtml")
element = session.find.css(element, all=False)
result = is_element_enabled(session, element.id)
assert_success(result, True)
def test_xml_always_not_enabled(session):
session.url = inline("""<note></note>""", doctype="xml")
element = session.find.css("note", all=False)
result = is_element_enabled(session, element.id)
assert_success(result, False)

View file

@ -0,0 +1,120 @@
# META: timeout=long
import pytest
from tests.support.asserts import assert_error, assert_dialog_handled, assert_success
from tests.support.inline import inline
def is_element_enabled(session, element_id):
return session.transport.send(
"GET",
"session/{session_id}/element/{element_id}/enabled".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 id=foo disabled>")
element = session.find.css("#foo", all=False)
create_dialog(dialog_type, text=dialog_type)
response = is_element_enabled(session, element.id)
assert_success(response, False)
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 disabled>")
element = session.find.css("#foo", all=False)
create_dialog(dialog_type, text=dialog_type)
response = is_element_enabled(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("<input id=foo disabled>")
element = session.find.css("#foo", all=False)
create_dialog(dialog_type, text=dialog_type)
response = is_element_enabled(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

@ -1,8 +1,10 @@
import pytest
from tests.support.asserts import assert_error
from conftest import product, flatten
from tests.new_session.support.create import invalid_data, invalid_extensions
from tests.support.asserts import assert_error
@pytest.mark.parametrize("value", [None, 1, "{}", []])
def test_invalid_capabilites(new_session, value):
@ -26,29 +28,6 @@ def test_invalid_first_match(new_session, add_browser_capabilities, value):
assert_error(response, "invalid argument")
invalid_data = [
("acceptInsecureCerts", [1, [], {}, "false"]),
("browserName", [1, [], {}, False]),
("browserVersion", [1, [], {}, False]),
("platformName", [1, [], {}, False]),
("pageLoadStrategy", [1, [], {}, False, "invalid", "NONE", "Eager", "eagerblah", "interactive",
" eager", "eager "]),
("proxy", [1, [], "{}", {"proxyType": "SYSTEM"}, {"proxyType": "systemSomething"},
{"proxy type": "pac"}, {"proxy-Type": "system"}, {"proxy_type": "system"},
{"proxytype": "system"}, {"PROXYTYPE": "system"}, {"proxyType": None},
{"proxyType": 1}, {"proxyType": []}, {"proxyType": {"value": "system"}},
{" proxyType": "system"}, {"proxyType ": "system"}, {"proxyType ": " system"},
{"proxyType": "system "}]),
("timeouts", [1, [], "{}", False, {"pageLOAD": 10}, {"page load": 10},
{"page load": 10}, {"pageLoad": "10"}, {"pageLoad": {"value": 10}},
{"invalid": 10}, {"pageLoad": -1}, {"pageLoad": 2**64},
{"pageLoad": None}, {"pageLoad": 1.1}, {"pageLoad": 10, "invalid": 10},
{" pageLoad": 10}, {"pageLoad ": 10}]),
("unhandledPromptBehavior", [1, [], {}, False, "DISMISS", "dismissABC", "Accept",
" dismiss", "dismiss "])
]
@pytest.mark.parametrize("body", [lambda key, value: {"alwaysMatch": {key: value}},
lambda key, value: {"firstMatch": [{key: value}]}])
@pytest.mark.parametrize("key,value", flatten(product(*item) for item in invalid_data))
@ -63,31 +42,6 @@ def test_invalid_values(new_session, add_browser_capabilities, body, key, value)
assert_error(response, "invalid argument")
invalid_extensions = [
"firefox",
"firefox_binary",
"firefoxOptions",
"chromeOptions",
"automaticInspection",
"automaticProfiling",
"platform",
"version",
"browser",
"platformVersion",
"javascriptEnabled",
"nativeEvents",
"seleniumProtocol",
"profile",
"trustAllSSLCertificates",
"initialBrowserUrl",
"requireWindowFocus",
"logFile",
"logLevel",
"safari.options",
"ensureCleanSession",
]
@pytest.mark.parametrize("body", [lambda key, value: {"alwaysMatch": {key: value}},
lambda key, value: {"firstMatch": [{key: value}]}])
@pytest.mark.parametrize("key", invalid_extensions)

View file

@ -1,15 +1,130 @@
# Note that we can only test things here all implementations must support
valid_data = [
("acceptInsecureCerts", [False, None]),
("browserName", [None]),
("browserVersion", [None]),
("platformName", [None]),
("pageLoadStrategy", ["none", "eager", "normal", None]),
("proxy", [None]),
("timeouts", [{"script": 0, "pageLoad": 2.0, "implicit": 2**53 - 1},
{"script": 50, "pageLoad": 25},
{"script": 500},
{}]),
("unhandledPromptBehavior", ["dismiss", "accept", None]),
("test:extension", [True, "abc", 123, [], {"key": "value"}, None]),
("acceptInsecureCerts", [
False, None,
]),
("browserName", [
None,
]),
("browserVersion", [
None,
]),
("platformName", [
None,
]),
("pageLoadStrategy", [
None,
"none",
"eager",
"normal",
]),
("proxy", [
None,
]),
("timeouts", [
None, {},
{"script": 0, "pageLoad": 2.0, "implicit": 2**53 - 1},
{"script": 50, "pageLoad": 25},
{"script": 500},
]),
("unhandledPromptBehavior", [
"dismiss",
"accept",
None,
]),
("test:extension", [
None, False, "abc", 123, [],
{"key": "value"},
]),
]
invalid_data = [
("acceptInsecureCerts", [
1, [], {}, "false",
]),
("browserName", [
1, [], {}, False,
]),
("browserVersion", [
1, [], {}, False,
]),
("platformName", [
1, [], {}, False,
]),
("pageLoadStrategy", [
1, [], {}, False,
"invalid",
"NONE",
"Eager",
"eagerblah",
"interactive",
" eager",
"eager "]),
("proxy", [
1, [], "{}",
{"proxyType": "SYSTEM"},
{"proxyType": "systemSomething"},
{"proxy type": "pac"},
{"proxy-Type": "system"},
{"proxy_type": "system"},
{"proxytype": "system"},
{"PROXYTYPE": "system"},
{"proxyType": None},
{"proxyType": 1},
{"proxyType": []},
{"proxyType": {"value": "system"}},
{" proxyType": "system"},
{"proxyType ": "system"},
{"proxyType ": " system"},
{"proxyType": "system "},
]),
("timeouts", [
1, [], "{}", False,
{"invalid": 10},
{"PAGELOAD": 10},
{"page load": 10},
{" pageLoad": 10},
{"pageLoad ": 10},
{"pageLoad": None},
{"pageLoad": False},
{"pageLoad": []},
{"pageLoad": "10"},
{"pageLoad": 2.5},
{"pageLoad": -1},
{"pageLoad": 2**53},
{"pageLoad": {"value": 10}},
{"pageLoad": 10, "invalid": 10},
]),
("unhandledPromptBehavior", [
1, [], {}, False,
"DISMISS",
"dismissABC",
"Accept",
" dismiss",
"dismiss ",
])
]
invalid_extensions = [
"firefox",
"firefox_binary",
"firefoxOptions",
"chromeOptions",
"automaticInspection",
"automaticProfiling",
"platform",
"version",
"browser",
"platformVersion",
"javascriptEnabled",
"nativeEvents",
"seleniumProtocol",
"profile",
"trustAllSSLCertificates",
"initialBrowserUrl",
"requireWindowFocus",
"logFile",
"logLevel",
"safari.options",
"ensureCleanSession",
]

View file

@ -6,6 +6,13 @@ from tests.support.asserts import assert_error, assert_success
from tests.support.inline import inline
@pytest.fixture
def page(session):
session.url = inline("""
<script>window.result = window.prompt('Enter Your Name: ', 'Name');</script>
""")
def send_alert_text(session, text=None):
return session.transport.send(
"POST", "session/{session_id}/alert/text".format(**vars(session)),
@ -18,64 +25,41 @@ def test_null_parameter_value(session, http):
assert_error(Response.from_http(response), "invalid argument")
def test_null_response_value(session, url):
session.url = inline("<script>window.result = window.prompt('Enter Your Name: ', 'Name');</script>")
def test_null_response_value(session, page):
response = send_alert_text(session, "Federer")
value = assert_success(response)
assert value is None
def test_no_browsing_context(session, closed_window):
response = send_alert_text(session, "foo")
assert_error(response, "no such window")
@pytest.mark.parametrize("text", [None, {}, [], 42, True])
def test_invalid_input(session, text):
session.url = inline("<script>window.result = window.prompt('Enter Your Name: ', 'Name');</script>")
def test_invalid_input(session, page, text):
response = send_alert_text(session, text)
assert_error(response, "invalid argument")
def test_no_browsing_context(session, closed_window):
response = send_alert_text(session, "Federer")
assert_error(response, "no such window")
def test_no_user_prompt(session):
response = send_alert_text(session, "Federer")
assert_error(response, "no such alert")
def test_alert_element_not_interactable(session):
session.url = inline("<script>window.alert('Hello');</script>")
@pytest.mark.parametrize("dialog_type", ["alert", "confirm"])
def test_alert_element_not_interactable(session, dialog_type):
session.url = inline("<script>window.{}('Hello');</script>".format(dialog_type))
response = send_alert_text(session, "Federer")
assert_error(response, "element not interactable")
def test_confirm_element_not_interactable(session):
session.url = inline("<script>window.confirm('Hello');</script>")
response = send_alert_text(session, "Federer")
assert_error(response, "element not interactable")
def test_send_alert_text(session):
session.url = inline("<script>window.result = window.prompt('Enter Your Name: ', 'Name');</script>")
send_response = send_alert_text(session, "Federer")
@pytest.mark.parametrize("text", ["", "Federer", " Fed erer "])
def test_send_alert_text(session, page, text):
send_response = send_alert_text(session, text)
assert_success(send_response)
accept_response = session.transport.send("POST", "session/{session_id}/alert/accept"
.format(session_id=session.session_id))
assert_success(accept_response)
assert session.execute_script("return window.result") == "Federer"
session.alert.accept()
def test_send_alert_text_with_whitespace(session):
session.url = inline("<script>window.result = window.prompt('Enter Your Name: ', 'Name');</script>")
send_response = send_alert_text(session, " Fed erer ")
assert_success(send_response)
accept_response = session.transport.send("POST", "session/{session_id}/alert/accept"
.format(session_id=session.session_id))
assert_success(accept_response)
assert session.execute_script("return window.result") == " Fed erer "
assert session.execute_script("return window.result") == text

View file

@ -1,3 +1,5 @@
import pytest
from webdriver.transport import Response
from tests.support.asserts import assert_error, assert_success
@ -16,14 +18,60 @@ def test_null_parameter_value(session, http):
def test_null_response_value(session):
response = set_timeouts(session, {"implicit": 1000})
timeouts = {"implicit": 10, "pageLoad": 10, "script": 10}
response = set_timeouts(session, timeouts)
value = assert_success(response)
assert value is None
response = set_timeouts(session, {"pageLoad": 1000})
value = assert_success(response)
assert value is None
response = set_timeouts(session, {"script": 1000})
value = assert_success(response)
assert value is None
@pytest.mark.parametrize("value", [1, "{}", False, []])
def test_parameters_invalid(session, value):
response = set_timeouts(session, value)
assert_error(response, "invalid argument")
def test_parameters_empty_no_change(session):
original = session.timeouts._get()
response = set_timeouts(session, {})
assert_success(response)
assert session.timeouts._get() == original
def test_key_invalid(session):
response = set_timeouts(session, {"foo": 1000})
assert_error(response, "invalid argument")
@pytest.mark.parametrize("typ", ["implicit", "pageLoad", "script"])
@pytest.mark.parametrize("value", [0, 2.0, 2**53 - 1])
def test_positive_integer(session, typ, value):
response = set_timeouts(session, {typ: value})
assert_success(response)
assert session.timeouts._get(typ) == value
@pytest.mark.parametrize("typ", ["implicit", "pageLoad", "script"])
@pytest.mark.parametrize("value", [None, [], {}, False, "10"])
def test_value_invalid_types(session, typ, value):
response = set_timeouts(session, {typ: value})
assert_error(response, "invalid argument")
@pytest.mark.parametrize("typ", ["implicit", "pageLoad", "script"])
@pytest.mark.parametrize("value", [-1, 2.5, 2**53])
def test_value_positive_integer(session, typ, value):
response = set_timeouts(session, {typ: value})
assert_error(response, "invalid argument")
def test_set_all_fields(session):
timeouts = {"implicit": 10, "pageLoad": 20, "script": 30}
response = set_timeouts(session, timeouts)
assert_success(response)
assert session.timeouts.implicit == 10
assert session.timeouts.page_load == 20
assert session.timeouts.script == 30

View file

@ -0,0 +1,62 @@
# META: timeout=long
import pytest
from tests.support.asserts import assert_success
def set_timeouts(session, timeouts):
return session.transport.send(
"POST", "session/{session_id}/timeouts".format(**vars(session)),
timeouts)
@pytest.fixture
def check_user_prompt_not_closed(session, create_dialog):
def check_user_prompt_not_closed(dialog_type):
create_dialog(dialog_type, text=dialog_type)
response = set_timeouts(session, {"script": 100})
assert_success(response)
assert session.alert.text == dialog_type
session.alert.dismiss()
assert session.timeouts.script == 100
return check_user_prompt_not_closed
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept"})
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_accept(check_user_prompt_not_closed, dialog_type):
check_user_prompt_not_closed(dialog_type)
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept and notify"})
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_accept_and_notify(check_user_prompt_not_closed, dialog_type):
check_user_prompt_not_closed(dialog_type)
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss"})
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_dismiss(check_user_prompt_not_closed, dialog_type):
check_user_prompt_not_closed(dialog_type)
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss and notify"})
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_dismiss_and_notify(check_user_prompt_not_closed, dialog_type):
check_user_prompt_not_closed(dialog_type)
@pytest.mark.capabilities({"unhandledPromptBehavior": "ignore"})
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_ignore(check_user_prompt_not_closed, dialog_type):
check_user_prompt_not_closed(dialog_type)
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_default(check_user_prompt_not_closed, dialog_type):
check_user_prompt_not_closed(dialog_type)

View file

@ -20,10 +20,10 @@ errors = {
"no such element": 404,
"no such frame": 404,
"no such window": 404,
"script timeout": 408,
"script timeout": 500,
"session not created": 500,
"stale element reference": 404,
"timeout": 408,
"timeout": 500,
"unable to set cookie": 500,
"unable to capture screen": 500,
"unexpected alert open": 500,

View file

@ -9,7 +9,7 @@ def inline(doc, doctype="html", mime="text/html;charset=utf-8", protocol="http")
mime = "text/html;charset=utf-8"
elif doctype == "xhtml":
mime = "application/xhtml+xml"
doc = r"""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
doc = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
@ -20,6 +20,9 @@ def inline(doc, doctype="html", mime="text/html;charset=utf-8", protocol="http")
{}
</body>
</html>""".format(doc)
elif doctype == "xml":
mime = "text/xml"
doc = """<?xml version="1.0" encoding="UTF-8"?>{}""".format(doc)
query = {"doc": doc}
if mime != "text/html;charset=utf8":
@ -41,8 +44,8 @@ def main(request, response):
rv = 404, [("Content-Type", "text/plain")], "Missing doc parameter in query"
else:
response.headers.update([
("Content-Type", content_type),
("X-XSS-Protection", "0")
("Content-Type", content_type),
("X-XSS-Protection", "0")
])
rv = doc
return rv

View file

@ -0,0 +1,40 @@
import base64
import imghdr
from tests.support.asserts import assert_error, assert_success
from tests.support.inline import inline
def take_element_screenshot(session, element_id):
return session.transport.send(
"GET",
"session/{session_id}/element/{element_id}/screenshot".format(
session_id=session.session_id,
element_id=element_id,
)
)
def test_no_browsing_context(session, closed_window):
response = take_element_screenshot(session, "foo")
assert_error(response, "no such window")
def test_screenshot(session):
session.url = inline("<input>")
element = session.find.css("input", all=False)
response = take_element_screenshot(session, element.id)
value = assert_success(response)
image = base64.decodestring(value)
assert imghdr.what("", image) == "png"
def test_stale(session):
session.url = inline("<input>")
element = session.find.css("input", all=False)
session.refresh()
result = take_element_screenshot(session, element.id)
assert_error(result, "stale element reference")

View file

@ -0,0 +1,74 @@
# META: timeout=long
import base64
import imghdr
import pytest
from tests.support.asserts import assert_success
from tests.support.inline import inline
def take_element_screenshot(session, element_id):
return session.transport.send(
"GET",
"session/{session_id}/element/{element_id}/screenshot".format(
session_id=session.session_id,
element_id=element_id,
)
)
@pytest.fixture
def check_user_prompt_not_closed_without_exception(session, create_dialog):
def check_user_prompt_not_closed_without_exception(dialog_type):
session.url = inline("<input/>")
element = session.find.css("input", all=False)
create_dialog(dialog_type, text=dialog_type)
response = take_element_screenshot(session, element.id)
value = assert_success(response)
image = base64.decodestring(value)
assert imghdr.what("", image) == "png"
assert session.alert.text == dialog_type
session.alert.dismiss()
return check_user_prompt_not_closed_without_exception
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept"})
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_accept(check_user_prompt_not_closed_without_exception, dialog_type):
check_user_prompt_not_closed_without_exception(dialog_type)
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept and notify"})
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_accept_and_notify(check_user_prompt_not_closed_without_exception, dialog_type):
check_user_prompt_not_closed_without_exception(dialog_type)
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss"})
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_dismiss(check_user_prompt_not_closed_without_exception, dialog_type):
check_user_prompt_not_closed_without_exception(dialog_type)
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss and notify"})
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_dismiss_and_notify(check_user_prompt_not_closed_without_exception, dialog_type):
check_user_prompt_not_closed_without_exception(dialog_type)
@pytest.mark.capabilities({"unhandledPromptBehavior": "ignore"})
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_ignore(check_user_prompt_not_closed_without_exception, dialog_type):
check_user_prompt_not_closed_without_exception(dialog_type)
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_default(check_user_prompt_not_closed_without_exception, dialog_type):
check_user_prompt_not_closed_without_exception(dialog_type)

View file

@ -0,0 +1,25 @@
import base64
import imghdr
from tests.support.asserts import assert_error, assert_success
from tests.support.inline import inline
def take_screenshot(session):
return session.transport.send(
"GET", "session/{session_id}/screenshot".format(**vars(session)))
def test_no_browsing_context(session, closed_window):
response = take_screenshot(session)
assert_error(response, "no such window")
def test_screenshot(session):
session.url = inline("<input>")
response = take_screenshot(session)
value = assert_success(response)
image = base64.decodestring(value)
assert imghdr.what("", image) == "png"

View file

@ -0,0 +1,68 @@
# META: timeout=long
import base64
import imghdr
import pytest
from tests.support.asserts import assert_success
from tests.support.inline import inline
def take_screenshot(session):
return session.transport.send(
"GET", "session/{session_id}/screenshot".format(**vars(session)))
@pytest.fixture
def check_user_prompt_not_closed_without_exception(session, create_dialog):
def check_user_prompt_not_closed_without_exception(dialog_type):
session.url = inline("<input/>")
create_dialog(dialog_type, text=dialog_type)
response = take_screenshot(session)
value = assert_success(response)
image = base64.decodestring(value)
assert imghdr.what("", image) == "png"
assert session.alert.text == dialog_type
session.alert.dismiss()
return check_user_prompt_not_closed_without_exception
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept"})
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_accept(check_user_prompt_not_closed_without_exception, dialog_type):
check_user_prompt_not_closed_without_exception(dialog_type)
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept and notify"})
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_accept_and_notify(check_user_prompt_not_closed_without_exception, dialog_type):
check_user_prompt_not_closed_without_exception(dialog_type)
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss"})
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_dismiss(check_user_prompt_not_closed_without_exception, dialog_type):
check_user_prompt_not_closed_without_exception(dialog_type)
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss and notify"})
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_dismiss_and_notify(check_user_prompt_not_closed_without_exception, dialog_type):
check_user_prompt_not_closed_without_exception(dialog_type)
@pytest.mark.capabilities({"unhandledPromptBehavior": "ignore"})
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_ignore(check_user_prompt_not_closed_without_exception, dialog_type):
check_user_prompt_not_closed_without_exception(dialog_type)
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_default(check_user_prompt_not_closed_without_exception, dialog_type):
check_user_prompt_not_closed_without_exception(dialog_type)