Update web-platform-tests to revision be5419e845d39089ba6dc338c1bd0fa279108317

This commit is contained in:
Josh Matthews 2018-01-04 13:44:24 -05:00
parent aa199307c8
commit 2b6f573eb5
3440 changed files with 109438 additions and 41750 deletions

View file

@ -4,3 +4,4 @@
@lukeis
@mjzffr
@shs96c
@whimboo

View file

@ -1,21 +0,0 @@
<!DOCTYPE html>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
test(function() {
if ("webdriver" in navigator) {
var descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(navigator), "webdriver");
assert_true(descriptor !== undefined);
assert_true(descriptor.configurable);
assert_true(descriptor.enumerable);
assert_true(descriptor.set === undefined);
assert_true(navigator.webdriver);
} else {
assert_true(navigator.webdriver === undefined);
}
}, "Test that the navigator.webdriver descriptor has expected properties or doesn't exist at all");
</script>
</body>
</html>

View file

@ -0,0 +1,49 @@
from tests.actions.support.keys import Keys, MODIFIER_KEY
from tests.actions.support.refine import get_keys
def test_mod_a_and_backspace_deletes_all_text(session, key_reporter, key_chain):
key_chain.send_keys("abc d") \
.key_down(MODIFIER_KEY) \
.key_down("a") \
.key_up(MODIFIER_KEY) \
.key_up("a") \
.key_down(Keys.BACKSPACE) \
.perform()
assert get_keys(key_reporter) == ""
def test_mod_a_mod_c_right_mod_v_pastes_text(session, key_reporter, key_chain):
initial = "abc d"
key_chain.send_keys(initial) \
.key_down(MODIFIER_KEY) \
.key_down("a") \
.key_up(MODIFIER_KEY) \
.key_up("a") \
.key_down(MODIFIER_KEY) \
.key_down("c") \
.key_up(MODIFIER_KEY) \
.key_up("c") \
.send_keys([Keys.RIGHT]) \
.key_down(MODIFIER_KEY) \
.key_down("v") \
.key_up(MODIFIER_KEY) \
.key_up("v") \
.perform()
assert get_keys(key_reporter) == initial * 2
def test_mod_a_mod_x_deletes_all_text(session, key_reporter, key_chain):
key_chain.send_keys("abc d") \
.key_down(MODIFIER_KEY) \
.key_down("a") \
.key_up(MODIFIER_KEY) \
.key_up("a") \
.key_down(MODIFIER_KEY) \
.key_down("x") \
.key_up(MODIFIER_KEY) \
.key_up("x") \
.perform()
assert get_keys(key_reporter) == ""

View file

@ -6,30 +6,55 @@ 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.CONTROL, "ctrlKey"),
(Keys.ALT, "altKey"),
(Keys.META, "metaKey"),
(Keys.SHIFT, "shiftKey"),
(Keys.R_CONTROL, "ctrlKey"),
(Keys.R_ALT, "altKey"),
(Keys.R_META, "metaKey"),
(Keys.R_SHIFT, "shiftKey"),
(Keys.ALT, "altKey"),
(Keys.R_ALT, "altKey"),
(Keys.META, "metaKey"),
(Keys.R_META, "metaKey"),
(Keys.SHIFT, "shiftKey"),
(Keys.R_SHIFT, "shiftKey"),
])
def test_modifier_click(session,
test_actions_page,
def test_modifier_click(mod_click_session,
key_chain,
mouse_chain,
modifier,
prop):
key_chain \
.pause(0) \
.pause(200) \
.key_down(modifier) \
.pause(200) \
.key_up(modifier)
outer = session.find.css("#outer", all=False)
outer = mod_click_session.find.css("#outer", all=False)
mouse_chain.click(element=outer)
session.actions.perform([key_chain.dict, mouse_chain.dict])
mod_click_session.actions.perform([key_chain.dict, mouse_chain.dict])
expected = [
{"type": "mousemove"},
{"type": "mousedown"},
@ -46,29 +71,47 @@ def test_modifier_click(session,
e.update(defaults)
if e["type"] != "mousemove":
e[prop] = True
filtered_events = [filter_dict(e, expected[0]) for e in get_events(session)]
filtered_events = [filter_dict(e, expected[0]) for e in get_events(mod_click_session)]
assert expected == filtered_events
def test_release_control_click(session, key_reporter, key_chain, mouse_chain):
def test_many_modifiers_click(mod_click_session, key_chain, mouse_chain):
outer = mod_click_session.find.css("#outer", all=False)
key_chain \
.pause(0) \
.key_down(Keys.CONTROL)
.key_down(Keys.CONTROL) \
.key_down(Keys.SHIFT) \
.pause(0) \
.key_up(Keys.CONTROL) \
.key_up(Keys.SHIFT)
mouse_chain \
.pointer_move(0, 0, origin=key_reporter) \
.pointer_move(0, 0, origin=outer) \
.pause(0) \
.pointer_down() \
.pointer_up() \
.pause(0) \
.pause(0) \
.pointer_down()
session.actions.perform([key_chain.dict, mouse_chain.dict])
session.execute_script("""
var keyReporter = document.getElementById("keys");
["mousedown", "mouseup"].forEach((e) => {
keyReporter.addEventListener(e, recordPointerEvent);
});
resetEvents();
""")
session.actions.release()
mod_click_session.actions.perform([key_chain.dict, mouse_chain.dict])
expected = [
{"type": "mousemove"},
# shift and ctrl presses
{"type": "mousedown"},
{"type": "mouseup"},
{"type": "keyup"},
{"type": "click"},
# no modifiers pressed
{"type": "mousedown"},
]
events = [filter_dict(e, expected[0]) for e in get_events(session)]
defaults = {
"altKey": False,
"metaKey": False,
"shiftKey": False,
"ctrlKey": False
}
for e in expected:
e.update(defaults)
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)]
assert events == expected

View file

@ -1,7 +1,8 @@
import pytest
from tests.support.inline import inline
from tests.actions.support.mouse import assert_move_to_coordinates, get_center
from tests.actions.support.refine import get_events, filter_dict
from tests.support.inline import inline
from tests.support.wait import wait
@ -10,13 +11,6 @@ def link_doc(dest):
return inline(content)
def get_center(rect):
return {
"x": rect["width"] / 2 + rect["x"],
"y": rect["height"] / 2 + rect["y"],
}
# TODO use pytest.approx once we upgrade to pytest > 3.0
def approx(n, m, tolerance=1):
return abs(n - m) <= tolerance
@ -33,11 +27,8 @@ def test_click_at_coordinates(session, test_actions_page, mouse_chain):
.perform()
events = get_events(session)
assert len(events) == 4
assert_move_to_coordinates(div_point, "outer", events)
for e in events:
if e["type"] != "mousemove":
assert e["pageX"] == div_point["x"]
assert e["pageY"] == div_point["y"]
assert e["target"] == "outer"
if e["type"] != "mousedown":
assert e["buttons"] == 0
assert e["button"] == 0
@ -89,7 +80,7 @@ def test_click_element_center(session, test_actions_page, mouse_chain):
assert e["target"] == "outer"
def test_click_navigation(session, url):
def test_click_navigation(session, url, release_actions):
destination = url("/webdriver/tests/actions/support/test_actions_wdspec.html")
start = link_doc(destination)
@ -112,7 +103,12 @@ def test_click_navigation(session, url):
@pytest.mark.parametrize("drag_duration", [0, 300, 800])
@pytest.mark.parametrize("dx, dy",
[(20, 0), (0, 15), (10, 15), (-20, 0), (10, -15), (-10, -15)])
def test_drag_and_drop(session, test_actions_page, mouse_chain, dx, dy, drag_duration):
def test_drag_and_drop(session,
test_actions_page,
mouse_chain,
dx,
dy,
drag_duration):
drag_target = session.find.css("#dragTarget", all=False)
initial_rect = drag_target.rect
initial_center = get_center(initial_rect)

View file

@ -0,0 +1,108 @@
import pytest
from tests.actions.support.mouse import assert_move_to_coordinates, get_center
from tests.actions.support.refine import get_events, filter_dict
_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):
div_point = {
"x": 82,
"y": 187,
}
mouse_chain \
.pointer_move(div_point["x"], div_point["y"]) \
.click() \
.pause(click_pause) \
.click() \
.perform()
events = get_events(dblclick_session)
assert_move_to_coordinates(div_point, "outer", events)
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_dblclick_with_pause_after_second_pointerdown(dblclick_session, mouse_chain):
outer = dblclick_session.find.css("#outer", all=False)
center = get_center(outer.rect)
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_center(outer.rect)
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:]

View file

@ -37,45 +37,3 @@ def test_release_no_actions_sends_no_events(session, key_reporter):
session.actions.release()
assert len(get_keys(key_reporter)) == 0
assert len(get_events(session)) == 0
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) \
.key_down(Keys.SHIFT) \
.pause(0) \
.key_up(Keys.CONTROL) \
.key_up(Keys.SHIFT)
mouse_chain \
.pointer_move(0, 0, origin=outer) \
.pause(0) \
.pointer_down() \
.pointer_up() \
.pause(0) \
.pause(0) \
.pointer_down()
session.actions.perform([key_chain.dict, mouse_chain.dict])
expected = [
{"type": "mousemove"},
# shift and ctrl presses
{"type": "mousedown"},
{"type": "mouseup"},
{"type": "click"},
# no modifiers pressed
{"type": "mousedown"},
]
defaults = {
"altKey": False,
"metaKey": False,
"shiftKey": False,
"ctrlKey": False
}
for e in expected:
e.update(defaults)
for e in expected[1:4]:
e["shiftKey"] = True
e["ctrlKey"] = True
events = [filter_dict(e, expected[0]) for e in get_events(session)]
assert events == expected

View file

@ -20,6 +20,7 @@ The Keys implementation.
"""
from inspect import getmembers
import sys
class Keys(object):
@ -740,3 +741,8 @@ ALL_EVENTS = {
"value": u"\ue040",
}
}
if sys.platform == 'darwin':
MODIFIER_KEY = Keys.META
else:
MODIFIER_KEY = Keys.CONTROL

View file

@ -0,0 +1,13 @@
def assert_move_to_coordinates(point, target, events):
for e in events:
if e["type"] != "mousemove":
assert e["pageX"] == point["x"]
assert e["pageY"] == point["y"]
assert e["target"] == target
def get_center(rect):
return {
"x": rect["width"] / 2 + rect["x"],
"y": rect["height"] / 2 + rect["y"],
}

View file

@ -1,14 +1,14 @@
from tests.support.fixtures import clear_all_cookies
from tests.support.fixtures import server_config
from datetime import datetime, timedelta
def test_add_domain_cookie(session, url):
def test_add_domain_cookie(session, url, server_config):
session.url = url("/common/blank.html")
clear_all_cookies(session)
create_cookie_request = {
"cookie": {
"name": "hello",
"value": "world",
"domain": "web-platform.test",
"domain": server_config["domains"][""],
"path": "/",
"httpOnly": False,
"secure": False
@ -36,16 +36,16 @@ def test_add_domain_cookie(session, url):
assert cookie["name"] == "hello"
assert cookie["value"] == "world"
assert cookie["domain"] == ".web-platform.test"
assert cookie["domain"] == ".%s" % server_config["domains"][""]
def test_add_cookie_for_ip(session, url, server_config):
def test_add_cookie_for_ip(session, url, server_config, configuration):
session.url = "http://127.0.0.1:%s/404" % (server_config["ports"]["http"][0])
clear_all_cookies(session)
create_cookie_request = {
"cookie": {
"name": "hello",
"value": "world",
"domain": "127.0.0.1",
"domain": configuration["host"],
"path": "/",
"httpOnly": False,
"secure": False
@ -74,3 +74,104 @@ def test_add_cookie_for_ip(session, url, server_config):
assert cookie["name"] == "hello"
assert cookie["value"] == "world"
assert cookie["domain"] == "127.0.0.1"
def test_add_non_session_cookie(session, url):
session.url = url("/common/blank.html")
clear_all_cookies(session)
a_year_from_now = int((datetime.utcnow() + timedelta(days=365)).strftime("%s"))
create_cookie_request = {
"cookie": {
"name": "hello",
"value": "world",
"expiry": a_year_from_now
}
}
result = session.transport.send("POST", "session/%s/cookie" % session.session_id, create_cookie_request)
assert result.status == 200
assert "value" in result.body
assert isinstance(result.body["value"], dict)
result = session.transport.send("GET", "session/%s/cookie" % session.session_id)
assert result.status == 200
assert "value" in result.body
assert isinstance(result.body["value"], list)
assert len(result.body["value"]) == 1
assert isinstance(result.body["value"][0], dict)
cookie = result.body["value"][0]
assert "name" in cookie
assert isinstance(cookie["name"], basestring)
assert "value" in cookie
assert isinstance(cookie["value"], basestring)
assert "expiry" in cookie
assert isinstance(cookie["expiry"], int)
assert cookie["name"] == "hello"
assert cookie["value"] == "world"
assert cookie["expiry"] == a_year_from_now
def test_add_session_cookie(session, url):
session.url = url("/common/blank.html")
clear_all_cookies(session)
create_cookie_request = {
"cookie": {
"name": "hello",
"value": "world"
}
}
result = session.transport.send("POST", "session/%s/cookie" % session.session_id, create_cookie_request)
assert result.status == 200
assert "value" in result.body
assert isinstance(result.body["value"], dict)
result = session.transport.send("GET", "session/%s/cookie" % session.session_id)
assert result.status == 200
assert "value" in result.body
assert isinstance(result.body["value"], list)
assert len(result.body["value"]) == 1
assert isinstance(result.body["value"][0], dict)
cookie = result.body["value"][0]
assert "name" in cookie
assert isinstance(cookie["name"], basestring)
assert "value" in cookie
assert isinstance(cookie["value"], basestring)
assert "expiry" in cookie
assert cookie.get("expiry") is None
assert cookie["name"] == "hello"
assert cookie["value"] == "world"
def test_add_session_cookie_with_leading_dot_character_in_domain(session, url, server_config):
session.url = url("/common/blank.html")
clear_all_cookies(session)
create_cookie_request = {
"cookie": {
"name": "hello",
"value": "world",
"domain": ".%s" % server_config["domains"][""]
}
}
result = session.transport.send("POST", "session/%s/cookie" % session.session_id, create_cookie_request)
assert result.status == 200
assert "value" in result.body
assert isinstance(result.body["value"], dict)
result = session.transport.send("GET", "session/%s/cookie" % session.session_id)
assert result.status == 200
assert "value" in result.body
assert isinstance(result.body["value"], list)
assert len(result.body["value"]) == 1
assert isinstance(result.body["value"][0], dict)
cookie = result.body["value"][0]
assert "name" in cookie
assert isinstance(cookie["name"], basestring)
assert "value" in cookie
assert isinstance(cookie["value"], basestring)
assert "domain" in cookie
assert isinstance(cookie["domain"], basestring)
assert cookie["name"] == "hello"
assert cookie["value"] == "world"
assert cookie["domain"] == ".%s" % server_config["domains"][""]

View file

@ -61,14 +61,14 @@ def test_get_named_cookie(session, url):
# convert from seconds since epoch
assert datetime.utcfromtimestamp(cookie["expiry"]).strftime(utc_string_format) == a_year_from_now
def test_duplicated_cookie(session, url):
def test_duplicated_cookie(session, url, server_config):
session.url = url("/common/blank.html")
clear_all_cookies(session)
create_cookie_request = {
"cookie": {
"name": "hello",
"value": "world",
"domain": "web-platform.test",
"domain": server_config["domains"][""],
"path": "/",
"httpOnly": False,
"secure": False
@ -79,7 +79,7 @@ def test_duplicated_cookie(session, url):
assert "value" in result.body
assert isinstance(result.body["value"], dict)
session.url = inline("<script>document.cookie = 'hello=newworld; domain=web-platform.test; path=/';</script>")
session.url = inline("<script>document.cookie = 'hello=newworld; domain=%s; path=/';</script>" % server_config["domains"][""])
result = session.transport.send("GET", "session/%s/cookie" % session.session_id)
assert result.status == 200
assert "value" in result.body

View file

@ -0,0 +1,14 @@
import pytest
from tests.support.inline import inline
# 15.1.3 "Let source be the result returned from the outerHTML IDL attribute
# of the document element"
def test_source_matches_outer_html(session):
session.url = inline("<html><head><title>Cheese</title><body>Peas")
expected_source = session.execute_script(
"return document.documentElement.outerHTML")
assert session.source == expected_source

View file

@ -0,0 +1,152 @@
from tests.support.asserts import assert_success
from tests.support.inline import inline
def 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))
def test_click_event_bubbles_to_parents(session):
session.url = inline("""
<style>
body * {
margin: 10px;
padding: 10px;
border: 1px solid blue;
}
</style>
<div id=three>THREE
<div id=two>TWO
<div id=one>ONE</div>
</div>
</div>
<script>
window.clicks = [];
for (let level of document.querySelectorAll("div")) {
level.addEventListener("click", ({currentTarget}) => {
window.clicks.push(currentTarget);
});
}
</script>
""")
three, two, one = session.find.css("div")
one.click()
clicks = session.execute_script("return window.clicks")
assert one in clicks
assert two in clicks
assert three in clicks
def test_spin_event_loop(session):
"""
Wait until the user agent event loop has spun enough times to
process the DOM events generated by clicking.
"""
session.url = inline("""
<style>
body * {
margin: 10px;
padding: 10px;
border: 1px solid blue;
}
</style>
<div id=three>THREE
<div id=two>TWO
<div id=one>ONE</div>
</div>
</div>
<script>
window.delayedClicks = [];
for (let level of document.querySelectorAll("div")) {
level.addEventListener("click", ({currentTarget}) => {
setTimeout(() => window.delayedClicks.push(currentTarget), 100);
});
}
</script>
""")
three, two, one = session.find.css("div")
one.click()
delayed_clicks = session.execute_script("return window.delayedClicks")
assert one in delayed_clicks
assert two in delayed_clicks
assert three in delayed_clicks
def test_element_disappears_during_click(session):
"""
When an element in the event bubbling order disappears (its CSS
display style is set to "none") during a click, Gecko and Blink
exhibit different behaviour. Whilst Chrome fires a "click"
DOM event on <body>, Firefox does not.
A WebDriver implementation may choose to wait for this event to let
the event loops spin enough times to let click events propagate,
so this is a corner case test that Firefox does not hang indefinitely.
"""
session.url = inline("""
<style>
#over,
#under {
position: absolute;
top: 8px;
left: 8px;
width: 100px;
height: 100px;
}
#over {
background: blue;
opacity: .5;
}
#under {
background: yellow;
}
#log {
margin-top: 120px;
}
</style>
<body id="body">
<div id=under></div>
<div id=over></div>
<div id=log></div>
</body>
<script>
let under = document.querySelector("#under");
let over = document.querySelector("#over");
let body = document.querySelector("body");
let log = document.querySelector("#log");
function logEvent({type, target, currentTarget}) {
log.innerHTML += "<p></p>";
log.lastElementChild.textContent = `${type} in ${target.id} (handled by ${currentTarget.id})`;
}
for (let ev of ["click", "mousedown", "mouseup"]) {
under.addEventListener(ev, logEvent);
over.addEventListener(ev, logEvent);
body.addEventListener(ev, logEvent);
}
over.addEventListener("mousedown", () => over.style.display = "none");
</script>
""")
over = session.find.css("#over", all=False)
# should not time out
response = click(session, over)
assert_success(response)

View file

@ -0,0 +1,22 @@
import pytest
import webdriver
from tests.support.asserts import assert_error
from tests.support.inline import inline
def click_element(session, element):
return session.transport.send(
"POST", "/session/{session_id}/element/{element_id}/click".format(**{
"session_id": session.session_id,
"element_id": element.id,
}))
def test_is_stale(session):
session.url = inline("<button>foo</button>")
button = session.find.css("button", all=False)
session.url = inline("<button>bar</button>")
response = click_element(session, button)
assert_error(response, "stale element reference")

View file

@ -71,3 +71,13 @@ def test_xhtml_namespace(session, using, value):
response = find_element(session, using, value)
value = assert_success(response)
assert_same_element(session, value, expected)
@pytest.mark.parametrize("using,value",
[("css selector", ":root"),
("tag name", "html"),
("xpath", "/html")])
def test_htmldocument(session, using, value):
session.url = inline("")
response = find_element(session, using, value)
assert_success(response)

View file

@ -72,3 +72,11 @@ def test_xhtml_namespace(session, using, value):
response = find_element(session, from_element.id, using, value)
value = assert_success(response)
assert_same_element(session, value, expected)
def test_parent_htmldocument(session):
session.url = inline("")
from_element = session.execute_script("return document.documentElement")
response = find_element(session, from_element.id, "xpath", "..")
assert_success(response)

View file

@ -77,3 +77,15 @@ def test_xhtml_namespace(session, using, value):
found_element = value[0]
assert_same_element(session, found_element, expected)
@pytest.mark.parametrize("using,value",
[("css selector", ":root"),
("tag name", "html"),
("xpath", "/html")])
def test_htmldocument(session, using, value):
session.url = inline("")
response = find_elements(session, using, value)
value = assert_success(response)
assert isinstance(value, list)
assert len(value) == 1

View file

@ -75,3 +75,13 @@ def test_xhtml_namespace(session, using, value):
found_element = value[0]
assert_same_element(session, found_element, expected)
def test_parent_htmldocument(session):
session.url = inline("")
from_element = session.execute_script("return document.documentElement")
response = find_elements(session, from_element.id, "xpath", "..")
value = assert_success(response)
assert isinstance(value, list)
assert len(value) == 1

View file

@ -2,9 +2,11 @@ from tests.support.asserts import assert_error, assert_dialog_handled, assert_sa
from tests.support.fixtures import create_dialog
from tests.support.inline import inline
def read_global(session, name):
return session.execute_script("return %s;" % name)
def get_active_element(session):
return session.transport.send("GET", "session/%s/element/active" % session.session_id)
@ -67,7 +69,7 @@ def test_handle_prompt_dismiss(new_session, add_browser_capabilites):
response = get_active_element(session)
assert_is_active_element(session, response)
assert_dialog_handled(session, "dismiss #2")
assert read_global(session, "dismiss2") is None
assert read_global(session, "dismiss2") is False
create_dialog(session)("prompt", text="dismiss #3", result_var="dismiss3")
@ -244,7 +246,7 @@ def test_success_iframe_content(session):
assert_is_active_element(session, response)
def test_sucess_without_body(session):
def test_missing_document_element(session):
session.url = inline("<body></body>")
session.execute_script("""
if (document.body.remove) {
@ -254,4 +256,4 @@ def test_sucess_without_body(session):
}""")
response = get_active_element(session)
assert_is_active_element(session, response)
assert_error(response, "no such element")

View file

@ -0,0 +1,136 @@
from tests.support.asserts import assert_error, assert_same_element, assert_success
from tests.support.inline import iframe, inline
def send_keys_to_element(session, element, text):
return session.transport.send(
"POST",
"/session/{session_id}/element/{element_id}/value".format(
session_id=session.session_id,
element_id=element.id),
{"text": text})
def test_body_is_interactable(session):
session.url = inline("""
<body onkeypress="document.getElementById('result').value += event.key">
<input type="text" id="result"/>
</body>
""")
element = session.find.css("body", all=False)
result = session.find.css("input", all=False)
# By default body is the active element
assert_same_element(session, element, session.active_element)
response = send_keys_to_element(session, element, "foo")
assert_success(response)
assert_same_element(session, element, session.active_element)
assert result.property("value") == "foo"
def test_document_element_is_interactable(session):
session.url = inline("""
<html onkeypress="document.getElementById('result').value += event.key">
<input type="text" id="result"/>
</html>
""")
body = session.find.css("body", all=False)
element = session.find.css(":root", all=False)
result = session.find.css("input", all=False)
# By default body is the active element
assert_same_element(session, body, session.active_element)
response = send_keys_to_element(session, element, "foo")
assert_success(response)
assert_same_element(session, element, session.active_element)
assert result.property("value") == "foo"
def test_iframe_is_interactable(session):
session.url = inline(iframe("""
<body onkeypress="document.getElementById('result').value += event.key">
<input type="text" id="result"/>
</body>
"""))
body = session.find.css("body", all=False)
frame = session.find.css("iframe", all=False)
# By default the body has the focus
assert_same_element(session, body, session.active_element)
response = send_keys_to_element(session, frame, "foo")
assert_success(response)
assert_same_element(session, frame, session.active_element)
# Any key events are immediately routed to the nested
# browsing context's active document.
session.switch_frame(frame)
result = session.find.css("input", all=False)
assert result.property("value") == "foo"
def test_transparent_element(session):
session.url = inline("<input style=\"opacity: 0;\">")
element = session.find.css("input", all=False)
response = send_keys_to_element(session, element, "foo")
assert_success(response)
assert element.property("value") == "foo"
def test_readonly_element(session):
session.url = inline("<input readonly>")
element = session.find.css("input", all=False)
response = send_keys_to_element(session, element, "foo")
assert_success(response)
assert element.property("value") == ""
def test_obscured_element(session):
session.url = inline("""
<input type="text" />
<div style="position: relative; top: -3em; height: 5em; background-color: blue"></div>
""")
element = session.find.css("input", all=False)
response = send_keys_to_element(session, element, "foo")
assert_success(response)
assert element.property("value") == "foo"
def test_not_a_focusable_element(session):
session.url = inline("<div>foo</div>")
element = session.find.css("div", all=False)
response = send_keys_to_element(session, element, "foo")
assert_error(response, "element not interactable")
def test_not_displayed_element(session):
session.url = inline("<input style=\"display: none\">")
element = session.find.css("input", all=False)
response = send_keys_to_element(session, element, "foo")
assert_error(response, "element not interactable")
def test_hidden_element(session):
session.url = inline("<input style=\"visibility: hidden\">")
element = session.find.css("input", all=False)
response = send_keys_to_element(session, element, "foo")
assert_error(response, "element not interactable")
def test_disabled_element(session):
session.url = inline("<input disabled=\"false\">")
element = session.find.css("input", all=False)
response = send_keys_to_element(session, element, "foo")
assert_error(response, "element not interactable")

View file

@ -0,0 +1,78 @@
from tests.support.asserts import assert_success
from tests.support.fixtures import is_element_in_viewport
from tests.support.inline import inline
def send_keys_to_element(session, element, text):
return session.transport.send(
"POST",
"/session/{session_id}/element/{element_id}/value".format(
session_id=session.session_id,
element_id=element.id),
{"text": text})
def test_element_outside_of_not_scrollable_viewport(session):
session.url = inline("<input style=\"position: relative; left: -9999px;\">")
element = session.find.css("input", all=False)
response = send_keys_to_element(session, element, "foo")
assert_success(response)
assert not is_element_in_viewport(session, element)
def test_element_outside_of_scrollable_viewport(session):
session.url = inline("<input style=\"margin-top: 102vh;\">")
element = session.find.css("input", all=False)
response = send_keys_to_element(session, element, "foo")
assert_success(response)
assert is_element_in_viewport(session, element)
def test_option_select_container_outside_of_scrollable_viewport(session):
session.url = inline("""
<select style="margin-top: 102vh;">
<option value="foo">foo</option>
<option value="bar" id="bar">bar</option>
</select>
""")
element = session.find.css("option#bar", all=False)
select = session.find.css("select", all=False)
response = send_keys_to_element(session, element, "bar")
assert_success(response)
assert is_element_in_viewport(session, select)
assert is_element_in_viewport(session, element)
def test_option_stays_outside_of_scrollable_viewport(session):
session.url = inline("""
<select multiple style="height: 105vh; margin-top: 100vh;">
<option value="foo" id="foo" style="height: 100vh;">foo</option>
<option value="bar" id="bar" style="background-color: yellow;">bar</option>
</select>
""")
select = session.find.css("select", all=False)
option_foo = session.find.css("option#foo", all=False)
option_bar = session.find.css("option#bar", all=False)
response = send_keys_to_element(session, option_bar, "bar")
assert_success(response)
assert is_element_in_viewport(session, select)
assert is_element_in_viewport(session, option_foo)
assert not is_element_in_viewport(session, option_bar)
def test_contenteditable_element_outside_of_scrollable_viewport(session):
session.url = inline("<div contenteditable style=\"margin-top: 102vh;\"></div>")
element = session.find.css("div", all=False)
response = send_keys_to_element(session, element, "foo")
assert_success(response)
assert is_element_in_viewport(session, element)

View file

@ -0,0 +1,60 @@
import pytest
from webdriver import error
# 15.2 Executing Script
def test_handle_prompt_accept(new_session, add_browser_capabilites):
_, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "accept"})}})
session.execute_async_script("window.alert('Hello');")
with pytest.raises(error.NoSuchAlertException):
session.alert.accept()
def test_handle_prompt_dismiss(new_session, add_browser_capabilites):
_, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "dismiss"})}})
session.execute_async_script("window.alert('Hello');")
with pytest.raises(error.NoSuchAlertException):
session.alert.dismiss()
def test_handle_prompt_dismiss_and_notify(new_session, add_browser_capabilites):
_, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "dismiss and notify"})}})
with pytest.raises(error.UnexpectedAlertOpenException):
session.execute_async_script("window.alert('Hello');")
with pytest.raises(error.NoSuchAlertException):
session.alert.dismiss()
def test_handle_prompt_accept_and_notify(new_session, add_browser_capabilites):
_, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "accept and notify"})}})
with pytest.raises(error.UnexpectedAlertOpenException):
session.execute_async_script("window.alert('Hello');")
with pytest.raises(error.NoSuchAlertException):
session.alert.accept()
def test_handle_prompt_ignore(new_session, add_browser_capabilites):
_, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "ignore"})}})
with pytest.raises(error.UnexpectedAlertOpenException):
session.execute_async_script("window.alert('Hello');")
session.alert.dismiss()
def test_handle_prompt_default(new_session, add_browser_capabilites):
_, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({})}})
with pytest.raises(error.UnexpectedAlertOpenException):
session.execute_async_script("window.alert('Hello');")
with pytest.raises(error.NoSuchAlertException):
session.alert.dismiss()
def test_handle_prompt_twice(new_session, add_browser_capabilites):
_, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "accept"})}})
session.execute_async_script("window.alert('Hello');window.alert('Bye');")
# The first alert has been accepted by the user prompt handler, the second one remains.
# FIXME: this is how browsers currently work, but the spec should clarify if this is the
# expected behavior, see https://github.com/w3c/webdriver/issues/1153.
assert session.alert.text == "Bye"
session.alert.dismiss()

View file

@ -0,0 +1,48 @@
from tests.support.asserts import assert_error
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(
session_id=session.session_id),
body)
def test_array(session):
response = execute_script(session, """
let arr = [];
arr.push(arr);
return arr;
""")
assert_error(response, "javascript error")
def test_object(session):
response = execute_script(session, """
let obj = {};
obj.reference = obj;
return obj;
""")
assert_error(response, "javascript error")
def test_array_in_object(session):
response = execute_script(session, """
let arr = [];
arr.push(arr);
return {arr};
""")
assert_error(response, "javascript error")
def test_object_in_array(session):
response = execute_script(session, """
let obj = {};
obj.reference = obj;
return [obj];
""")
assert_error(response, "javascript error")

View file

@ -0,0 +1,60 @@
import pytest
from webdriver import error
# 15.2 Executing Script
def test_handle_prompt_accept(new_session, add_browser_capabilites):
_, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "accept"})}})
session.execute_script("window.alert('Hello');")
with pytest.raises(error.NoSuchAlertException):
session.alert.accept()
def test_handle_prompt_dismiss(new_session, add_browser_capabilites):
_, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "dismiss"})}})
session.execute_script("window.alert('Hello');")
with pytest.raises(error.NoSuchAlertException):
session.alert.dismiss()
def test_handle_prompt_dismiss_and_notify(new_session, add_browser_capabilites):
_, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "dismiss and notify"})}})
with pytest.raises(error.UnexpectedAlertOpenException):
session.execute_script("window.alert('Hello');")
with pytest.raises(error.NoSuchAlertException):
session.alert.dismiss()
def test_handle_prompt_accept_and_notify(new_session, add_browser_capabilites):
_, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "accept and notify"})}})
with pytest.raises(error.UnexpectedAlertOpenException):
session.execute_script("window.alert('Hello');")
with pytest.raises(error.NoSuchAlertException):
session.alert.accept()
def test_handle_prompt_ignore(new_session, add_browser_capabilites):
_, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "ignore"})}})
with pytest.raises(error.UnexpectedAlertOpenException):
session.execute_script("window.alert('Hello');")
session.alert.dismiss()
def test_handle_prompt_default(new_session, add_browser_capabilites):
_, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({})}})
with pytest.raises(error.UnexpectedAlertOpenException):
session.execute_script("window.alert('Hello');")
with pytest.raises(error.NoSuchAlertException):
session.alert.dismiss()
def test_handle_prompt_twice(new_session, add_browser_capabilites):
_, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "accept"})}})
session.execute_script("window.alert('Hello');window.alert('Bye');")
# The first alert has been accepted by the user prompt handler, the second one remains.
# FIXME: this is how browsers currently work, but the spec should clarify if this is the
# expected behavior, see https://github.com/w3c/webdriver/issues/1153.
assert session.alert.text == "Bye"
session.alert.dismiss()

View file

@ -151,11 +151,10 @@ def test_payload(session):
assert response.status == 200
assert isinstance(response.body["value"], dict)
value = response.body["value"]
assert "width" in value
assert "height" in value
assert "x" in value
assert "y" in value
assert isinstance(value["width"], int)
assert isinstance(value["height"], int)
assert isinstance(value["x"], int)
assert isinstance(value["y"], int)
expected = session.execute_script("""return {
x: window.screenX,
y: window.screenY,
width: window.outerWidth,
height: window.outerHeight
}""")
assert expected == value

View file

@ -147,9 +147,9 @@ def test_clear_content_editable_resettable_element(session, element):
url = element[1] + """<input id=focusCheck type=checkbox>
<input id=blurCheck type=checkbox>
<script>
var id = %s
document.getElementById("id").addEventListener("focus", checkFocus);
document.getElementById("id").addEventListener("blur", checkBlur);
var id = "%s";
document.getElementById(id).addEventListener("focus", checkFocus);
document.getElementById(id).addEventListener("blur", checkBlur);
document.getElementById("empty").addEventListener("focus", checkFocus);
document.getElementById("empty").addEventListener("blur", checkBlur);
@ -163,15 +163,15 @@ def test_clear_content_editable_resettable_element(session, element):
session.url = inline(url)
# Step 1
empty_element = session.find.css("#empty", all=False)
test_clear_element_helper(session, empty_element, False)
clear_element_test_helper(session, empty_element, False)
session.execute_script("document.getElementById(\"focusCheck\").checked = false;")
session.execute_script("document.getElementById(\"blurCheck\").checked = false;")
# Step 2 - 4
test_element = session.find.css("#" + element[0], all=False)
test_clear_element_helper(session, test_element, True)
clear_element_test_helper(session, test_element, True)
def test_clear_element_helper(session, element, value):
def clear_element_test_helper(session, element, value):
response = clear(session, element)
assert_success(response)
response = session.execute_script("return document.getElementById(\"focusCheck\").checked;")

View file

@ -1,15 +1,38 @@
<!doctype html>
<meta charset=utf-8>
<title>WebDriver interface test</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<!DOCTYPE html>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src=/resources/WebIDLParser.js></script>
<script src=/resources/idlharness.js></script>
<script>
var t = new IdlArray();
t.add_untested_idls("interface Navigator {};");
t.add_idls("partial interface Navigator { readonly attribute boolean webdriver; };");
t.add_objects({Navigator: ["navigator"]});
t.test();
<script type=text/plain class=untested>
[Exposed=Window]
interface Navigator {
// objects implementing this interface also implement the interfaces given below
};
</script>
<script type=text/plain>
Navigator includes NavigatorAutomationInformation;
interface mixin NavigatorAutomationInformation {
readonly attribute boolean webdriver;
// always returns true
};
</script>
<script>
"use strict";
if ("webdriver" in navigator) {
test(() => assert_true(navigator.webdriver), "navigator.webdriver is always true");
var idlArray = new IdlArray();
[].forEach.call(document.querySelectorAll("script[type=text\\/plain]"), function(node) {
if (node.className == "untested") {
idlArray.add_untested_idls(node.textContent);
} else {
idlArray.add_idls(node.textContent);
}
});
idlArray.test();
} else {
done();
}
</script>

View file

@ -4,6 +4,7 @@ import types
from tests.support.inline import inline
from tests.support.asserts import assert_error, assert_success
from tests.support.wait import wait
alert_doc = inline("<script>window.alert()</script>")
frame_doc = inline("<p>frame")
@ -75,8 +76,11 @@ def test_set_malformed_url(session):
assert_error(result, "invalid argument")
def test_get_current_url_after_modified_location(session):
start = session.transport.send("GET", "session/%s/url" % session.session_id)
session.execute_script("window.location.href = 'about:blank#wd_test_modification'")
wait(session,
lambda s: s.transport.send("GET", "session/%s/url" % session.session_id) != start.body["value"],
"URL did not change")
result = session.transport.send("GET", "session/%s/url" % session.session_id)
assert_success(result, "about:blank#wd_test_modification")

View file

@ -0,0 +1,45 @@
import pytest
import json
def test_get_status_no_session(http):
with http.get("/status") as response:
# GET /status should never return an error
assert response.status == 200
# parse JSON response and unwrap 'value' property
parsed_obj = json.loads(response.read().decode('utf-8'))
value = parsed_obj["value"]
# Let body be a new JSON Object with the following properties:
# "ready"
# The remote end's readiness state.
assert value["ready"] in [True, False]
# "message"
# An implementation-defined string explaining the remote end's
# readiness state.
assert isinstance(value["message"], basestring)
def test_status_with_session_running_on_endpoint_node(new_session, add_browser_capabilites):
# For an endpoint node, the maximum number of active
# sessions is 1: https://www.w3.org/TR/webdriver/#dfn-maximum-active-sessions
# A session is open, so we expect `ready` to be False
# 8.3 step 1.
_, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({})}})
value = session.send_command("GET", "status")
assert value["ready"] == False
assert "message" in value
session.end()
# Active session count is 0, meaning that the
# readiness state of the server should be True
# 8.3 step 1. Again
value = session.send_command("GET", "status")
assert value["ready"] == True
assert "message" in value

View file

@ -1,21 +0,0 @@
import pytest
import json
def test_get_status_no_session(http):
with http.get("/status") as response:
# GET /status should never return an error
assert response.status == 200
# parse JSON response and unwrap 'value' property
parsed_obj = json.loads(response.read().decode('utf-8'))
value = parsed_obj["value"]
# Let body be a new JSON Object with the following properties:
# "ready"
# The remote end's readiness state.
assert value["ready"] in [True, False]
# "message"
# An implementation-defined string explaining the remote end's
# readiness state.
assert isinstance(value["message"], basestring)

View file

@ -1,5 +1,6 @@
from webdriver import Element, WebDriverException
# WebDriver specification ID: dfn-error-response-data
errors = {
"element click intercepted": 400,
@ -21,7 +22,7 @@ errors = {
"no such window": 404,
"script timeout": 408,
"session not created": 500,
"stale element reference": 400,
"stale element reference": 404,
"timeout": 408,
"unable to set cookie": 500,
"unable to capture screen": 500,
@ -32,6 +33,7 @@ errors = {
"unsupported operation": 500,
}
# WebDriver specification ID: dfn-send-an-error
#
# > When required to send an error, with error code, a remote end must run the
@ -54,12 +56,13 @@ errors = {
# >
# > 5. Send a response with status and data as arguments.
def assert_error(response, error_code):
"""Verify that the provided wdclient.Response instance described a valid
error response as defined by `dfn-send-an-error` and the provided error
code.
"""
Verify that the provided webdriver.Response instance described
a valid error response as defined by `dfn-send-an-error` and
the provided error code.
:param response: wdclient.Response instance
:param error_code: string value of the expected "error code"
:param response: ``webdriver.Response`` instance.
:param error_code: String value of the expected error code
"""
assert response.status == errors[error_code]
assert "value" in response.body
@ -69,13 +72,13 @@ def assert_error(response, error_code):
def assert_success(response, value=None):
"""Verify that the provided wdclient.Response instance described a valid
error response as defined by `dfn-send-an-error` and the provided error
code.
"""
Verify that the provided webdriver.Response instance described
a valid error response as defined by `dfn-send-an-error` and
the provided error code.
:param response: wdclient.Response instance.
:param response: ``webdriver.Response`` instance.
:param value: Expected value of the response body, if any.
"""
assert response.status == 200, str(response.error)
@ -97,7 +100,7 @@ def assert_dialog_handled(session, expected_text):
except:
assert (result.status == 200 and
result.body["value"] != expected_text), (
"Dialog with text '%s' was not handled." % expected_text)
"Dialog with text '%s' was not handled." % expected_text)
def assert_same_element(session, a, b):
@ -122,7 +125,7 @@ def assert_same_element(session, a, b):
return
message = ("Expected element references to describe the same element, " +
"but they did not.")
"but they did not.")
# Attempt to provide more information, accounting for possible errors such
# as stale element references or not visible elements.

View file

@ -8,6 +8,7 @@ import mozlog
from tests.support.asserts import assert_error
from tests.support.http_request import HTTPRequest
from tests.support.wait import wait
from tests.support import merge_dictionaries
default_host = "http://127.0.0.1"
@ -254,10 +255,31 @@ def create_dialog(session):
session.send_session_command("POST",
"execute/async",
{"script": spawn, "args": []})
wait(session,
lambda s: s.send_session_command("GET", "alert/text") == text,
"modal has not appeared",
timeout=15,
ignored_exceptions=webdriver.NoSuchAlertException)
return create_dialog
def clear_all_cookies(session):
"""Removes all cookies associated with the current active document"""
session.transport.send("DELETE", "session/%s/cookie" % session.session_id)
def is_element_in_viewport(session, element):
"""Check if element is outside of the viewport"""
return session.execute_script("""
let el = arguments[0];
let rect = el.getBoundingClientRect();
let viewport = {
height: window.innerHeight || document.documentElement.clientHeight,
width: window.innerWidth || document.documentElement.clientWidth,
};
return !(rect.right < 0 || rect.bottom < 0 ||
rect.left > viewport.width || rect.top > viewport.height)
""", args=(element,))

View file

@ -1,10 +1,13 @@
import sys
import time
class TimeoutException(Exception):
pass
def wait(session, condition, message, interval=0.1, timeout=5):
def wait(session, condition, message,
interval=0.1, timeout=5, ignored_exceptions=Exception):
""" Poll a condition until it's true or the timeout ellapses.
:param session: WebDriver session to use with `condition`
@ -12,6 +15,8 @@ def wait(session, condition, message, interval=0.1, timeout=5):
:param message: failure description to display in case the timeout is reached
:param interval: seconds between each call to `condition`. Default: 0.1
:param timeout: seconds until we stop polling. Default: 5
:param ignored_exceptions: Exceptions that are expected and can be ignored.
Default: Exception
"""
start = time.time()
@ -19,10 +24,15 @@ def wait(session, condition, message, interval=0.1, timeout=5):
while not (time.time() >= end):
next_step = time.time() + interval
success = condition(session)
try:
success = condition(session)
except ignored_exceptions:
last_exc = sys.exc_info()[0]
success = False
next_interval = max(next_step - time.time(), 0)
if not success:
time.sleep(next_interval)
continue
return success
raise TimeoutException("Timed out after %d seconds: %s" % (timeout, message))

View file

@ -1,4 +1,5 @@
from tests.support.asserts import assert_error, assert_success
from tests.support.inline import inline
def accept_alert(session):
@ -25,14 +26,14 @@ def test_no_user_prompt(session):
def test_accept_alert(session):
# 18.2 step 3
session.execute_script("window.alert(\"Hello\");")
session.url = inline("<script>window.alert('Hello');</script>")
response = accept_alert(session)
assert_success(response)
def test_accept_confirm(session):
# 18.2 step 3
session.execute_script("window.result = window.confirm(\"Hello\");")
session.url = inline("<script>window.result = window.confirm('Hello');</script>")
response = accept_alert(session)
assert_success(response)
assert session.execute_script("return window.result") is True
@ -40,7 +41,7 @@ def test_accept_confirm(session):
def test_accept_prompt(session):
# 18.2 step 3
session.execute_script("window.result = window.prompt(\"Enter Your Name: \", \"Federer\");")
session.url = inline("<script>window.result = window.prompt('Enter Your Name: ', 'Federer');</script>")
response = accept_alert(session)
assert_success(response)
assert session.execute_script("return window.result") == "Federer"

View file

@ -1,4 +1,5 @@
from tests.support.asserts import assert_error, assert_success
from tests.support.inline import inline
def dismiss_alert(session):
@ -25,14 +26,14 @@ def test_no_user_prompt(session):
def test_dismiss_alert(session):
# 18.1 step 3
session.execute_script("window.alert(\"Hello\");")
session.url = inline("<script>window.alert('Hello');</script>")
response = dismiss_alert(session)
assert_success(response)
def test_dismiss_confirm(session):
# 18.1 step 3
session.execute_script("window.result = window.confirm(\"Hello\");")
session.url = inline("<script>window.result = window.confirm('Hello');</script>")
response = dismiss_alert(session)
assert_success(response)
assert session.execute_script("return window.result;") is False
@ -40,7 +41,7 @@ def test_dismiss_confirm(session):
def test_dismiss_prompt(session):
# 18.1 step 3
session.execute_script("window.result = window.prompt(\"Enter Your Name: \", \"Federer\");")
session.url = inline("<script>window.result = window.prompt('Enter Your Name: ', 'Federer');</script>")
response = dismiss_alert(session)
assert_success(response)
assert session.execute_script("return window.result") is None

View file

@ -1,4 +1,5 @@
from tests.support.asserts import assert_error, assert_success
from tests.support.inline import inline
def get_dialog_text(session):
@ -25,7 +26,7 @@ def test_no_user_prompt(session):
def test_get_alert_text(session):
# 18.3 step 3
session.execute_script("window.alert(\"Hello\");")
session.url = inline("<script>window.alert('Hello');</script>")
response = get_dialog_text(session)
assert_success(response)
assert isinstance(response.body, dict)
@ -37,7 +38,7 @@ def test_get_alert_text(session):
def test_get_confirm_text(session):
# 18.3 step 3
session.execute_script("window.confirm(\"Hello\");")
session.url = inline("<script>window.confirm('Hello');</script>")
response = get_dialog_text(session)
assert_success(response)
assert isinstance(response.body, dict)
@ -49,7 +50,7 @@ def test_get_confirm_text(session):
def test_get_prompt_text(session):
# 18.3 step 3
session.execute_script("window.prompt(\"Enter Your Name: \", \"Federer\");")
session.url = inline("<script>window.prompt('Enter Your Name: ', 'Federer');</script>")
response = get_dialog_text(session)
assert_success(response)
assert isinstance(response.body, dict)

View file

@ -1,6 +1,7 @@
import pytest
from tests.support.asserts import assert_error, assert_success
from tests.support.inline import inline
def send_alert_text(session, body=None):
return session.transport.send("POST", "session/{session_id}/alert/text"
@ -12,7 +13,7 @@ def send_alert_text(session, body=None):
@pytest.mark.parametrize("text", [None, {}, [], 42, True])
def test_invalid_input(session, text):
# 18.4 step 2
session.execute_script("window.result = window.prompt(\"Enter Your Name: \", \"Name\");")
session.url = inline("<script>window.result = window.prompt('Enter Your Name: ', 'Name');</script>")
response = send_alert_text(session, {"text": text})
assert_error(response, "invalid argument")
@ -35,7 +36,7 @@ def test_no_user_prompt(session):
def test_alert_element_not_interactable(session):
# 18.4 step 5
session.execute_script("window.alert(\"Hello\");")
session.url = inline("<script>window.alert('Hello');</script>")
body = {"text": "Federer"}
response = send_alert_text(session, body)
assert_error(response, "element not interactable")
@ -43,7 +44,7 @@ def test_alert_element_not_interactable(session):
def test_confirm_element_not_interactable(session):
# 18.4 step 5
session.execute_script("window.confirm(\"Hello\");")
session.url = inline("<script>window.confirm('Hello');</script>")
body = {"text": "Federer"}
response = send_alert_text(session, body)
assert_error(response, "element not interactable")
@ -51,7 +52,7 @@ def test_confirm_element_not_interactable(session):
def test_send_alert_text(session):
# 18.4 step 6
session.execute_script("window.result = window.prompt(\"Enter Your Name: \", \"Name\");")
session.url = inline("<script>window.result = window.prompt('Enter Your Name: ', 'Name');</script>")
body = {"text": "Federer"}
send_response = send_alert_text(session, body)
assert_success(send_response)
@ -63,7 +64,7 @@ def test_send_alert_text(session):
def test_send_alert_text_with_whitespace(session):
# 18.4 step 6
session.execute_script("window.result = window.prompt(\"Enter Your Name: \", \"Name\");")
session.url = inline("<script>window.result = window.prompt('Enter Your Name: ', 'Name');</script>")
body = {"text": " Fed erer "}
send_response = send_alert_text(session, body)
assert_success(send_response)