mirror of
https://github.com/servo/servo.git
synced 2025-08-11 00:15:32 +01:00
Update web-platform-tests to revision 4a5223502fa660ce03e470af6a61c8bc26c5a8ee
This commit is contained in:
parent
c5f7c9ccf3
commit
e891345f26
1328 changed files with 36632 additions and 20588 deletions
|
@ -1,39 +1,9 @@
|
|||
# META: timeout=long
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.actions.support.refine import filter_dict, get_events
|
||||
from tests.actions.support.keys import Keys
|
||||
|
||||
|
||||
# Using local fixtures because we want to start a new session between
|
||||
# each test, otherwise the clicks in each test interfere with each other.
|
||||
@pytest.fixture(autouse=True)
|
||||
def release_actions(mod_click_session, request):
|
||||
request.addfinalizer(mod_click_session.actions.release)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mod_click_session(new_session, url, add_browser_capabilites):
|
||||
_, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({})}})
|
||||
session.url = url("/webdriver/tests/actions/support/test_actions_wdspec.html")
|
||||
|
||||
return session
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def key_chain(mod_click_session):
|
||||
return mod_click_session.actions.sequence("key", "keyboard_id")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mouse_chain(mod_click_session):
|
||||
return mod_click_session.actions.sequence(
|
||||
"pointer",
|
||||
"pointer_id",
|
||||
{"pointerType": "mouse"})
|
||||
|
||||
|
||||
@pytest.mark.parametrize("modifier, prop", [
|
||||
(Keys.ALT, "altKey"),
|
||||
(Keys.R_ALT, "altKey"),
|
||||
|
@ -42,19 +12,15 @@ def mouse_chain(mod_click_session):
|
|||
(Keys.SHIFT, "shiftKey"),
|
||||
(Keys.R_SHIFT, "shiftKey"),
|
||||
])
|
||||
def test_modifier_click(mod_click_session,
|
||||
key_chain,
|
||||
mouse_chain,
|
||||
modifier,
|
||||
prop):
|
||||
def test_modifier_click(session, test_actions_page, key_chain, mouse_chain, modifier, prop):
|
||||
key_chain \
|
||||
.pause(200) \
|
||||
.key_down(modifier) \
|
||||
.pause(200) \
|
||||
.key_up(modifier)
|
||||
outer = mod_click_session.find.css("#outer", all=False)
|
||||
outer = session.find.css("#outer", all=False)
|
||||
mouse_chain.click(element=outer)
|
||||
mod_click_session.actions.perform([key_chain.dict, mouse_chain.dict])
|
||||
session.actions.perform([key_chain.dict, mouse_chain.dict])
|
||||
expected = [
|
||||
{"type": "mousemove"},
|
||||
{"type": "mousedown"},
|
||||
|
@ -71,12 +37,12 @@ def test_modifier_click(mod_click_session,
|
|||
e.update(defaults)
|
||||
if e["type"] != "mousemove":
|
||||
e[prop] = True
|
||||
filtered_events = [filter_dict(e, expected[0]) for e in get_events(mod_click_session)]
|
||||
filtered_events = [filter_dict(e, expected[0]) for e in get_events(session)]
|
||||
assert expected == filtered_events
|
||||
|
||||
|
||||
def test_many_modifiers_click(mod_click_session, key_chain, mouse_chain):
|
||||
outer = mod_click_session.find.css("#outer", all=False)
|
||||
def test_many_modifiers_click(session, test_actions_page, key_chain, mouse_chain):
|
||||
outer = session.find.css("#outer", all=False)
|
||||
key_chain \
|
||||
.pause(0) \
|
||||
.key_down(Keys.CONTROL) \
|
||||
|
@ -92,7 +58,7 @@ def test_many_modifiers_click(mod_click_session, key_chain, mouse_chain):
|
|||
.pause(0) \
|
||||
.pause(0) \
|
||||
.pointer_down()
|
||||
mod_click_session.actions.perform([key_chain.dict, mouse_chain.dict])
|
||||
session.actions.perform([key_chain.dict, mouse_chain.dict])
|
||||
expected = [
|
||||
{"type": "mousemove"},
|
||||
# shift and ctrl presses
|
||||
|
@ -113,5 +79,5 @@ def test_many_modifiers_click(mod_click_session, key_chain, mouse_chain):
|
|||
for e in expected[1:4]:
|
||||
e["shiftKey"] = True
|
||||
e["ctrlKey"] = True
|
||||
events = [filter_dict(e, expected[0]) for e in get_events(mod_click_session)]
|
||||
events = [filter_dict(e, expected[0]) for e in get_events(session)]
|
||||
assert events == expected
|
||||
|
|
|
@ -1,40 +1,11 @@
|
|||
import pytest
|
||||
|
||||
from tests.actions.support.mouse import get_inview_center, get_viewport_rect
|
||||
from tests.actions.support.refine import get_events, filter_dict
|
||||
from tests.support.asserts import assert_move_to_coordinates
|
||||
|
||||
|
||||
_DBLCLICK_INTERVAL = 640
|
||||
|
||||
|
||||
# Using local fixtures because we want to start a new session between
|
||||
# each test, otherwise the clicks in each test interfere with each other.
|
||||
@pytest.fixture(autouse=True)
|
||||
def release_actions(dblclick_session, request):
|
||||
# release all actions after each test
|
||||
# equivalent to a teardown_function, but with access to session fixture
|
||||
request.addfinalizer(dblclick_session.actions.release)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def dblclick_session(new_session, url, add_browser_capabilites):
|
||||
_, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({})}})
|
||||
session.url = url("/webdriver/tests/actions/support/test_actions_wdspec.html")
|
||||
|
||||
return session
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mouse_chain(dblclick_session):
|
||||
return dblclick_session.actions.sequence(
|
||||
"pointer",
|
||||
"pointer_id",
|
||||
{"pointerType": "mouse"})
|
||||
|
||||
|
||||
@pytest.mark.parametrize("click_pause", [0, 200])
|
||||
def test_dblclick_at_coordinates(dblclick_session, mouse_chain, click_pause):
|
||||
def test_dblclick_at_coordinates(session, test_actions_page, mouse_chain, click_pause):
|
||||
div_point = {
|
||||
"x": 82,
|
||||
"y": 187,
|
||||
|
@ -45,7 +16,7 @@ def test_dblclick_at_coordinates(dblclick_session, mouse_chain, click_pause):
|
|||
.pause(click_pause) \
|
||||
.click() \
|
||||
.perform()
|
||||
events = get_events(dblclick_session)
|
||||
events = get_events(session)
|
||||
assert_move_to_coordinates(div_point, "outer", events)
|
||||
expected = [
|
||||
{"type": "mousedown", "button": 0},
|
||||
|
@ -59,51 +30,3 @@ def test_dblclick_at_coordinates(dblclick_session, mouse_chain, click_pause):
|
|||
assert len(events) == 8
|
||||
filtered_events = [filter_dict(e, expected[0]) for e in events]
|
||||
assert expected == filtered_events[1:]
|
||||
|
||||
|
||||
def test_dblclick_with_pause_after_second_pointerdown(dblclick_session, mouse_chain):
|
||||
outer = dblclick_session.find.css("#outer", all=False)
|
||||
center = get_inview_center(outer.rect, get_viewport_rect(dblclick_session))
|
||||
mouse_chain \
|
||||
.pointer_move(int(center["x"]), int(center["y"])) \
|
||||
.click() \
|
||||
.pointer_down() \
|
||||
.pause(_DBLCLICK_INTERVAL + 10) \
|
||||
.pointer_up() \
|
||||
.perform()
|
||||
events = get_events(dblclick_session)
|
||||
expected = [
|
||||
{"type": "mousedown", "button": 0},
|
||||
{"type": "mouseup", "button": 0},
|
||||
{"type": "click", "button": 0},
|
||||
{"type": "mousedown", "button": 0},
|
||||
{"type": "mouseup", "button": 0},
|
||||
{"type": "click", "button": 0},
|
||||
{"type": "dblclick", "button": 0},
|
||||
]
|
||||
assert len(events) == 8
|
||||
filtered_events = [filter_dict(e, expected[0]) for e in events]
|
||||
assert expected == filtered_events[1:]
|
||||
|
||||
|
||||
def test_no_dblclick(dblclick_session, mouse_chain):
|
||||
outer = dblclick_session.find.css("#outer", all=False)
|
||||
center = get_inview_center(outer.rect, get_viewport_rect(dblclick_session))
|
||||
mouse_chain \
|
||||
.pointer_move(int(center["x"]), int(center["y"])) \
|
||||
.click() \
|
||||
.pause(_DBLCLICK_INTERVAL + 10) \
|
||||
.click() \
|
||||
.perform()
|
||||
events = get_events(dblclick_session)
|
||||
expected = [
|
||||
{"type": "mousedown", "button": 0},
|
||||
{"type": "mouseup", "button": 0},
|
||||
{"type": "click", "button": 0},
|
||||
{"type": "mousedown", "button": 0},
|
||||
{"type": "mouseup", "button": 0},
|
||||
{"type": "click", "button": 0},
|
||||
]
|
||||
assert len(events) == 7
|
||||
filtered_events = [filter_dict(e, expected[0]) for e in events]
|
||||
assert expected == filtered_events[1:]
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
from tests.actions.support.mouse import get_inview_center, get_viewport_rect
|
||||
from tests.actions.support.refine import get_events, filter_dict
|
||||
|
||||
_DBLCLICK_INTERVAL = 640
|
||||
|
||||
|
||||
def test_dblclick_with_pause_after_second_pointerdown(session, test_actions_page, mouse_chain):
|
||||
outer = session.find.css("#outer", all=False)
|
||||
center = get_inview_center(outer.rect, get_viewport_rect(session))
|
||||
mouse_chain \
|
||||
.pointer_move(int(center["x"]), int(center["y"])) \
|
||||
.click() \
|
||||
.pointer_down() \
|
||||
.pause(_DBLCLICK_INTERVAL + 10) \
|
||||
.pointer_up() \
|
||||
.perform()
|
||||
events = get_events(session)
|
||||
expected = [
|
||||
{"type": "mousedown", "button": 0},
|
||||
{"type": "mouseup", "button": 0},
|
||||
{"type": "click", "button": 0},
|
||||
{"type": "mousedown", "button": 0},
|
||||
{"type": "mouseup", "button": 0},
|
||||
{"type": "click", "button": 0},
|
||||
{"type": "dblclick", "button": 0},
|
||||
]
|
||||
assert len(events) == 8
|
||||
filtered_events = [filter_dict(e, expected[0]) for e in events]
|
||||
assert expected == filtered_events[1:]
|
||||
|
||||
|
||||
def test_no_dblclick(session, test_actions_page, mouse_chain):
|
||||
outer = session.find.css("#outer", all=False)
|
||||
center = get_inview_center(outer.rect, get_viewport_rect(session))
|
||||
mouse_chain \
|
||||
.pointer_move(int(center["x"]), int(center["y"])) \
|
||||
.click() \
|
||||
.pause(_DBLCLICK_INTERVAL + 10) \
|
||||
.click() \
|
||||
.perform()
|
||||
events = get_events(session)
|
||||
expected = [
|
||||
{"type": "mousedown", "button": 0},
|
||||
{"type": "mouseup", "button": 0},
|
||||
{"type": "click", "button": 0},
|
||||
{"type": "mousedown", "button": 0},
|
||||
{"type": "mouseup", "button": 0},
|
||||
{"type": "click", "button": 0},
|
||||
]
|
||||
assert len(events) == 7
|
||||
filtered_events = [filter_dict(e, expected[0]) for e in events]
|
||||
assert expected == filtered_events[1:]
|
|
@ -5,7 +5,7 @@ import time
|
|||
from tests.support.fixtures import configuration
|
||||
from tests.actions.support.keys import ALL_EVENTS, Keys
|
||||
from tests.actions.support.refine import filter_dict, get_keys, get_events
|
||||
|
||||
from webdriver import error
|
||||
|
||||
@pytest.mark.parametrize("name,expected", ALL_EVENTS.items())
|
||||
def test_webdriver_special_key_sends_keydown(session,
|
||||
|
@ -47,3 +47,37 @@ def test_webdriver_special_key_sends_keydown(session,
|
|||
assert entered_keys == expected["key"]
|
||||
else:
|
||||
assert len(entered_keys) == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value", [
|
||||
(u"f"),
|
||||
(u"\u0BA8\u0BBF"),
|
||||
(u"\u1100\u1161\u11A8"),
|
||||
])
|
||||
def test_multiple_codepoint_keys_behave_correctly(session,
|
||||
key_reporter,
|
||||
key_chain,
|
||||
value):
|
||||
key_chain \
|
||||
.key_down(value) \
|
||||
.key_up(value) \
|
||||
.perform()
|
||||
|
||||
assert get_keys(key_reporter) == value
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value", [
|
||||
(u"fa"),
|
||||
(u"\u0BA8\u0BBFb"),
|
||||
(u"\u0BA8\u0BBF\u0BA8"),
|
||||
(u"\u1100\u1161\u11A8c")
|
||||
])
|
||||
def test_invalid_multiple_codepoint_keys_fail(session,
|
||||
key_reporter,
|
||||
key_chain,
|
||||
value):
|
||||
with pytest.raises(error.InvalidArgumentException):
|
||||
key_chain \
|
||||
.key_down(value) \
|
||||
.key_up(value) \
|
||||
.perform()
|
|
@ -0,0 +1,158 @@
|
|||
import os
|
||||
|
||||
from tests.support.asserts import assert_same_element, assert_success
|
||||
from tests.support.inline import inline
|
||||
|
||||
|
||||
def execute_async_script(session, script, args=None):
|
||||
if args is None:
|
||||
args = []
|
||||
body = {"script": script, "args": args}
|
||||
return session.transport.send(
|
||||
"POST",
|
||||
"/session/{session_id}/execute/async".format(**vars(session)),
|
||||
body)
|
||||
|
||||
|
||||
def test_arguments(session):
|
||||
response = execute_async_script(session, """
|
||||
let [resolve] = arguments;
|
||||
function func() {
|
||||
return arguments;
|
||||
}
|
||||
resolve(func("foo", "bar"));
|
||||
""")
|
||||
assert_success(response, [u"foo", u"bar"])
|
||||
|
||||
|
||||
def test_array(session):
|
||||
response = execute_async_script(session, """
|
||||
let [resolve] = arguments;
|
||||
resolve([1, 2]);
|
||||
""")
|
||||
assert_success(response, [1, 2])
|
||||
|
||||
|
||||
def test_file_list(session, tmpdir):
|
||||
files = [tmpdir.join("foo.txt"), tmpdir.join("bar.txt")]
|
||||
|
||||
session.url = inline("<input type=file multiple>")
|
||||
upload = session.find.css("input", all=False)
|
||||
for file in files:
|
||||
file.write("morn morn")
|
||||
upload.send_keys(str(file))
|
||||
|
||||
response = execute_async_script(session, """
|
||||
let [resolve] = arguments;
|
||||
resolve(document.querySelector('input').files);
|
||||
""")
|
||||
value = assert_success(response)
|
||||
assert isinstance(value, list)
|
||||
assert len(value) == len(files)
|
||||
for expected, actual in zip(files, value):
|
||||
assert isinstance(actual, dict)
|
||||
assert "name" in actual
|
||||
assert isinstance(actual["name"], basestring)
|
||||
assert os.path.basename(str(expected)) == actual["name"]
|
||||
|
||||
|
||||
def test_html_all_collection(session):
|
||||
session.url = inline("""
|
||||
<p>foo
|
||||
<p>bar
|
||||
""")
|
||||
html = session.find.css("html", all=False)
|
||||
head = session.find.css("head", all=False)
|
||||
body = session.find.css("body", all=False)
|
||||
ps = session.find.css("p")
|
||||
|
||||
response = execute_async_script(session, """
|
||||
let [resolve] = arguments;
|
||||
resolve(document.all);
|
||||
""")
|
||||
value = assert_success(response)
|
||||
assert isinstance(value, list)
|
||||
# <html>, <head>, <body>, <p>, <p>
|
||||
assert len(value) == 5
|
||||
|
||||
assert_same_element(session, html, value[0])
|
||||
assert_same_element(session, head, value[1])
|
||||
assert_same_element(session, body, value[2])
|
||||
assert_same_element(session, ps[0], value[3])
|
||||
assert_same_element(session, ps[1], value[4])
|
||||
|
||||
|
||||
def test_html_collection(session):
|
||||
session.url = inline("""
|
||||
<p>foo
|
||||
<p>bar
|
||||
""")
|
||||
ps = session.find.css("p")
|
||||
|
||||
response = execute_async_script(session, """
|
||||
let [resolve] = arguments;
|
||||
resolve(document.getElementsByTagName('p'));
|
||||
""")
|
||||
value = assert_success(response)
|
||||
assert isinstance(value, list)
|
||||
assert len(value) == 2
|
||||
for expected, actual in zip(ps, value):
|
||||
assert_same_element(session, expected, actual)
|
||||
|
||||
|
||||
def test_html_form_controls_collection(session):
|
||||
session.url = inline("""
|
||||
<form>
|
||||
<input>
|
||||
<input>
|
||||
</form>
|
||||
""")
|
||||
inputs = session.find.css("input")
|
||||
|
||||
response = execute_async_script(session, """
|
||||
let [resolve] = arguments;
|
||||
resolve(document.forms[0].elements);
|
||||
""")
|
||||
value = assert_success(response)
|
||||
assert isinstance(value, list)
|
||||
assert len(value) == 2
|
||||
for expected, actual in zip(inputs, value):
|
||||
assert_same_element(session, expected, actual)
|
||||
|
||||
|
||||
def test_html_options_collection(session):
|
||||
session.url = inline("""
|
||||
<select>
|
||||
<option>
|
||||
<option>
|
||||
</select>
|
||||
""")
|
||||
options = session.find.css("option")
|
||||
|
||||
response = execute_async_script(session, """
|
||||
let [resolve] = arguments;
|
||||
resolve(document.querySelector('select').options);
|
||||
""")
|
||||
value = assert_success(response)
|
||||
assert isinstance(value, list)
|
||||
assert len(value) == 2
|
||||
for expected, actual in zip(options, value):
|
||||
assert_same_element(session, expected, actual)
|
||||
|
||||
|
||||
def test_node_list(session):
|
||||
session.url = inline("""
|
||||
<p>foo
|
||||
<p>bar
|
||||
""")
|
||||
ps = session.find.css("p")
|
||||
|
||||
response = execute_async_script(session, """
|
||||
let [resolve] = arguments;
|
||||
resolve(document.querySelectorAll('p'));
|
||||
""")
|
||||
value = assert_success(response)
|
||||
assert isinstance(value, list)
|
||||
assert len(value) == 2
|
||||
for expected, actual in zip(ps, value):
|
||||
assert_same_element(session, expected, actual)
|
|
@ -7,52 +7,66 @@ from webdriver import error
|
|||
|
||||
def test_handle_prompt_accept(new_session, add_browser_capabilites):
|
||||
_, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "accept"})}})
|
||||
session.execute_async_script("window.alert('Hello');")
|
||||
value = session.execute_async_script("window.alert('Hello');")
|
||||
assert value is None
|
||||
title = session.title
|
||||
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_async_script("window.alert('Hello');")
|
||||
value = session.execute_async_script("window.alert('Hello');")
|
||||
assert value is None
|
||||
title = session.title
|
||||
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"})}})
|
||||
value = session.execute_async_script("window.alert('Hello');")
|
||||
assert value is None
|
||||
with pytest.raises(error.UnexpectedAlertOpenException):
|
||||
session.execute_async_script("window.alert('Hello');")
|
||||
title = session.title
|
||||
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"})}})
|
||||
value = session.execute_async_script("window.alert('Hello');")
|
||||
assert value is None
|
||||
with pytest.raises(error.UnexpectedAlertOpenException):
|
||||
session.execute_async_script("window.alert('Hello');")
|
||||
title = session.title
|
||||
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"})}})
|
||||
value = session.execute_async_script("window.alert('Hello');")
|
||||
assert value is None
|
||||
with pytest.raises(error.UnexpectedAlertOpenException):
|
||||
session.execute_async_script("window.alert('Hello');")
|
||||
title = session.title
|
||||
session.alert.dismiss()
|
||||
|
||||
|
||||
def test_handle_prompt_default(new_session, add_browser_capabilites):
|
||||
_, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({})}})
|
||||
value = session.execute_async_script("window.alert('Hello');")
|
||||
assert value is None
|
||||
with pytest.raises(error.UnexpectedAlertOpenException):
|
||||
session.execute_async_script("window.alert('Hello');")
|
||||
title = session.title
|
||||
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_async_script("window.alert('Hello');window.alert('Bye');")
|
||||
value = session.execute_async_script("window.alert('Hello');window.alert('Bye');")
|
||||
assert value is None
|
||||
session.alert.dismiss()
|
||||
# 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.
|
||||
|
|
|
@ -0,0 +1,136 @@
|
|||
import os
|
||||
|
||||
from tests.support.asserts import assert_same_element, assert_success
|
||||
from tests.support.inline import inline
|
||||
|
||||
|
||||
def execute_script(session, script, args=None):
|
||||
if args is None:
|
||||
args = []
|
||||
body = {"script": script, "args": args}
|
||||
return session.transport.send(
|
||||
"POST",
|
||||
"/session/{session_id}/execute/sync".format(**vars(session)),
|
||||
body)
|
||||
|
||||
|
||||
def test_arguments(session):
|
||||
response = execute_script(session, """
|
||||
function func() {
|
||||
return arguments;
|
||||
}
|
||||
return func("foo", "bar");
|
||||
""")
|
||||
assert_success(response, [u"foo", u"bar"])
|
||||
|
||||
|
||||
def test_array(session):
|
||||
response = execute_script(session, "return [1, 2]")
|
||||
assert_success(response, [1, 2])
|
||||
|
||||
|
||||
def test_file_list(session, tmpdir):
|
||||
files = [tmpdir.join("foo.txt"), tmpdir.join("bar.txt")]
|
||||
|
||||
session.url = inline("<input type=file multiple>")
|
||||
upload = session.find.css("input", all=False)
|
||||
for file in files:
|
||||
file.write("morn morn")
|
||||
upload.send_keys(str(file))
|
||||
|
||||
response = execute_script(session, "return document.querySelector('input').files")
|
||||
value = assert_success(response)
|
||||
assert isinstance(value, list)
|
||||
assert len(value) == len(files)
|
||||
for expected, actual in zip(files, value):
|
||||
assert isinstance(actual, dict)
|
||||
assert "name" in actual
|
||||
assert isinstance(actual["name"], basestring)
|
||||
assert os.path.basename(str(expected)) == actual["name"]
|
||||
|
||||
|
||||
def test_html_all_collection(session):
|
||||
session.url = inline("""
|
||||
<p>foo
|
||||
<p>bar
|
||||
""")
|
||||
html = session.find.css("html", all=False)
|
||||
head = session.find.css("head", all=False)
|
||||
body = session.find.css("body", all=False)
|
||||
ps = session.find.css("p")
|
||||
|
||||
response = execute_script(session, "return document.all")
|
||||
value = assert_success(response)
|
||||
assert isinstance(value, list)
|
||||
# <html>, <head>, <body>, <p>, <p>
|
||||
assert len(value) == 5
|
||||
|
||||
assert_same_element(session, html, value[0])
|
||||
assert_same_element(session, head, value[1])
|
||||
assert_same_element(session, body, value[2])
|
||||
assert_same_element(session, ps[0], value[3])
|
||||
assert_same_element(session, ps[1], value[4])
|
||||
|
||||
|
||||
def test_html_collection(session):
|
||||
session.url = inline("""
|
||||
<p>foo
|
||||
<p>bar
|
||||
""")
|
||||
ps = session.find.css("p")
|
||||
|
||||
response = execute_script(session, "return document.getElementsByTagName('p')")
|
||||
value = assert_success(response)
|
||||
assert isinstance(value, list)
|
||||
assert len(value) == 2
|
||||
for expected, actual in zip(ps, value):
|
||||
assert_same_element(session, expected, actual)
|
||||
|
||||
|
||||
def test_html_form_controls_collection(session):
|
||||
session.url = inline("""
|
||||
<form>
|
||||
<input>
|
||||
<input>
|
||||
</form>
|
||||
""")
|
||||
inputs = session.find.css("input")
|
||||
|
||||
response = execute_script(session, "return document.forms[0].elements")
|
||||
value = assert_success(response)
|
||||
assert isinstance(value, list)
|
||||
assert len(value) == 2
|
||||
for expected, actual in zip(inputs, value):
|
||||
assert_same_element(session, expected, actual)
|
||||
|
||||
|
||||
def test_html_options_collection(session):
|
||||
session.url = inline("""
|
||||
<select>
|
||||
<option>
|
||||
<option>
|
||||
</select>
|
||||
""")
|
||||
options = session.find.css("option")
|
||||
|
||||
response = execute_script(session, "return document.querySelector('select').options")
|
||||
value = assert_success(response)
|
||||
assert isinstance(value, list)
|
||||
assert len(value) == 2
|
||||
for expected, actual in zip(options, value):
|
||||
assert_same_element(session, expected, actual)
|
||||
|
||||
|
||||
def test_node_list(session):
|
||||
session.url = inline("""
|
||||
<p>foo
|
||||
<p>bar
|
||||
""")
|
||||
ps = session.find.css("p")
|
||||
|
||||
response = execute_script(session, "return document.querySelectorAll('p')")
|
||||
value = assert_success(response)
|
||||
assert isinstance(value, list)
|
||||
assert len(value) == 2
|
||||
for expected, actual in zip(ps, value):
|
||||
assert_same_element(session, expected, actual)
|
|
@ -7,52 +7,66 @@ from webdriver import error
|
|||
|
||||
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');")
|
||||
value = session.execute_script("window.alert('Hello');")
|
||||
assert value is None
|
||||
title = session.title
|
||||
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');")
|
||||
value = session.execute_script("window.alert('Hello');")
|
||||
assert value is None
|
||||
title = session.title
|
||||
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"})}})
|
||||
value = session.execute_script("window.alert('Hello');")
|
||||
assert value is None
|
||||
with pytest.raises(error.UnexpectedAlertOpenException):
|
||||
session.execute_script("window.alert('Hello');")
|
||||
title = session.title
|
||||
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"})}})
|
||||
value = session.execute_script("window.alert('Hello');")
|
||||
assert value is None
|
||||
with pytest.raises(error.UnexpectedAlertOpenException):
|
||||
session.execute_script("window.alert('Hello');")
|
||||
title = session.title
|
||||
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"})}})
|
||||
value = session.execute_script("window.alert('Hello');")
|
||||
assert value is None
|
||||
with pytest.raises(error.UnexpectedAlertOpenException):
|
||||
session.execute_script("window.alert('Hello');")
|
||||
title = session.title
|
||||
session.alert.dismiss()
|
||||
|
||||
|
||||
def test_handle_prompt_default(new_session, add_browser_capabilites):
|
||||
_, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({})}})
|
||||
value = session.execute_script("window.alert('Hello');")
|
||||
assert value is None
|
||||
with pytest.raises(error.UnexpectedAlertOpenException):
|
||||
session.execute_script("window.alert('Hello');")
|
||||
title = session.title
|
||||
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');")
|
||||
value = session.execute_script("window.alert('Hello');window.alert('Bye');")
|
||||
assert value is None
|
||||
session.alert.dismiss()
|
||||
# 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.
|
||||
|
|
|
@ -214,7 +214,7 @@ def add_browser_capabilites(configuration):
|
|||
def url(server_config):
|
||||
def inner(path, protocol="http", query="", fragment=""):
|
||||
port = server_config["ports"][protocol][0]
|
||||
host = "%s:%s" % (server_config["host"], port)
|
||||
host = "%s:%s" % (server_config["browser_host"], port)
|
||||
return urlparse.urlunsplit((protocol, host, path, query, fragment))
|
||||
|
||||
inner.__name__ = "url"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue