Update web-platform-tests to revision 077bb422b7bb21491a414e334bc594d83ca9e55b

This commit is contained in:
WPT Sync Bot 2018-10-16 21:24:11 -04:00
parent aa9591137a
commit b2341e328d
248 changed files with 2930 additions and 1961 deletions

View file

@ -9,7 +9,7 @@ import webdriver
from tests.support import defaults
from tests.support.helpers import cleanup_session
from tests.support.http_request import HTTPRequest
from tests.support.wait import wait
from tests.support.sync import Poll
_current_session = None
@ -208,11 +208,12 @@ def create_dialog(session):
}, 0);
""", args=(dialog_type, text))
wait(session,
lambda s: s.alert.text == text,
"No user prompt with text '{}' detected".format(text),
timeout=15,
ignored_exceptions=webdriver.NoSuchAlertException)
wait = Poll(
session,
timeout=15,
ignored_exceptions=webdriver.NoSuchAlertException,
message="No user prompt with text '{}' detected".format(text))
wait.until(lambda s: s.alert.text == text)
return create_dialog

View file

@ -1,6 +1,7 @@
# META: timeout=long
import pytest
import time
from webdriver import Element
@ -47,7 +48,7 @@ def test_null_response_value(session):
def test_no_browsing_context(session, closed_window):
element = Element("foo", session)
element = Element("foo" + str(time.time()), session)
response = element_clear(session, element)
assert_error(response, "no such window")

View file

@ -4,7 +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
from tests.support.sync import Poll
alert_doc = inline("<script>window.alert()</script>")
frame_doc = inline("<p>frame")
@ -69,9 +69,8 @@ def test_set_malformed_url(session):
def test_get_current_url_after_modified_location(session):
start = get_current_url(session)
session.execute_script("window.location.href = 'about:blank#wd_test_modification'")
wait(session,
lambda _: get_current_url(session).body["value"] != start.body["value"],
"URL did not change")
Poll(session, message="URL did not change").until(
lambda s: get_current_url(s).body["value"] != start.body["value"])
result = get_current_url(session)
assert_success(result, "about:blank#wd_test_modification")

View file

@ -1,6 +1,6 @@
from tests.support.asserts import assert_error, assert_success
from tests.support.inline import inline
from tests.support.wait import wait
from tests.support.sync import Poll
def read_global(session, name):
@ -39,12 +39,14 @@ def test_title_without_element(session):
def test_title_after_modification(session):
def title():
return read_global(session, "document.title")
session.url = inline("<title>Initial</title><h2>Hello</h2>")
session.execute_script("document.title = 'Updated'")
wait(session,
lambda s: assert_success(get_title(s)) == read_global(session, "document.title"),
"Document title doesn't match '{}'".format(read_global(session, "document.title")))
wait = Poll(session, message='Document title does not match "{}"'.format(title()))
wait.until(lambda s: assert_success(get_title(s)) == title())
def test_title_strip_and_collapse(session):

View file

@ -6,7 +6,7 @@ from tests.perform_actions.support.mouse import get_inview_center, get_viewport_
from tests.perform_actions.support.refine import filter_dict, get_events
from tests.support.asserts import assert_move_to_coordinates
from tests.support.inline import inline
from tests.support.wait import wait
from tests.support.sync import Poll
def link_doc(dest):
@ -101,11 +101,11 @@ def test_click_navigation(session, url):
error_message = "Did not navigate to %s" % destination
click(session.find.css("#link", all=False))
wait(session, lambda s: s.url == destination, error_message)
Poll(session, message=error_message).until(lambda s: s.url == destination)
# repeat steps to check behaviour after document unload
session.url = start
click(session.find.css("#link", all=False))
wait(session, lambda s: s.url == destination, error_message)
Poll(session, message=error_message).until(lambda s: s.url == destination)
@pytest.mark.parametrize("drag_duration", [0, 300, 800])

View file

@ -0,0 +1,146 @@
import collections
import sys
import time
from webdriver import error
DEFAULT_TIMEOUT = 5
DEFAULT_INTERVAL = 0.1
class Poll(object):
"""
An explicit conditional utility primitive for polling until a
condition evaluates to something truthy.
A `Poll` instance defines the maximum amount of time to wait
for a condition, as well as the frequency with which to check
the condition. Furthermore, the user may configure the wait
to ignore specific types of exceptions whilst waiting, such as
`error.NoSuchElementException` when searching for an element
on the page.
"""
def __init__(self,
session,
timeout=DEFAULT_TIMEOUT,
interval=DEFAULT_INTERVAL,
raises=error.TimeoutException,
message=None,
ignored_exceptions=None,
clock=time):
"""
Configure the poller to have a custom timeout, interval,
and list of ignored exceptions. Optionally a different time
implementation than the one provided by the standard library
(`time`) can also be provided.
Sample usage::
# Wait 30 seconds for window to open,
# checking for its presence once every 5 seconds.
from support.sync import Poll
wait = Poll(session, timeout=30, interval=5,
ignored_exceptions=error.NoSuchWindowException)
window = wait.until(lambda s: s.switch_to_window(42))
:param session: The input value to be provided to conditions,
usually a `webdriver.Session` instance.
:param timeout: How long to wait for the evaluated condition
to become true.
:param interval: How often the condition should be evaluated.
In reality the interval may be greater as the cost of
evaluating the condition function. If that is not the case the
interval for the next condition function call is shortend to keep
the original interval sequence as best as possible.
:param raises: Optional exception to raise when poll elapses.
If not used, an `error.TimeoutException` is raised.
If it is `None`, no exception is raised on the poll elapsing.
:param message: An optional message to include in `raises`'s
message if the `until` condition times out.
:param ignored_exceptions: Ignore specific types of exceptions
whilst waiting for the condition. Any exceptions not
whitelisted will be allowed to propagate, terminating the
wait.
:param clock: Allows overriding the use of the runtime's
default time library. See `sync.SystemClock` for
implementation details.
"""
self.session = session
self.timeout = timeout
self.interval = interval
self.exc_cls = raises
self.exc_msg = message
self.clock = clock
exceptions = []
if ignored_exceptions is not None:
if isinstance(ignored_exceptions, collections.Iterable):
exceptions.extend(iter(ignored_exceptions))
else:
exceptions.append(ignored_exceptions)
self.exceptions = tuple(set(exceptions))
def until(self, condition):
"""
This will repeatedly evaluate `condition` in anticipation
for a truthy return value, or the timeout to expire.
A condition that returns `None` or does not evaluate to
true will fully elapse its timeout before raising, unless
the `raises` keyword argument is `None`, in which case the
condition's return value is propagated unconditionally.
If an exception is raised in `condition` and it's not ignored,
this function will raise immediately. If the exception is
ignored it will be swallowed and polling will resume until
either the condition meets the return requirements or the
timeout duration is reached.
:param condition: A callable function whose return value will
be returned by this function.
"""
rv = None
last_exc = None
start = self.clock.time()
end = start + self.timeout
while not self.clock.time() >= end:
try:
next = self.clock.time() + self.interval
rv = condition(self.session)
except (KeyboardInterrupt, SystemExit):
raise
except self.exceptions:
last_exc = sys.exc_info()
# re-adjust the interval depending on how long
# the callback took to evaluate the condition
interval_new = max(next - self.clock.time(), 0)
if not rv:
self.clock.sleep(interval_new)
continue
if rv is not None:
return rv
self.clock.sleep(interval_new)
if self.exc_cls is not None:
elapsed = round((self.clock.time() - start), 1)
message = ""
if self.exc_msg is not None:
message = " with message: {}".format(self.exc_msg)
raise self.exc_cls(
"Timed out after {} seconds{}".format(elapsed, message),
cause=last_exc)
else:
return rv

View file

@ -1,38 +0,0 @@
import sys
import time
class TimeoutException(Exception):
pass
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`
:param condition: function that accepts a WebDriver session and returns a boolean
: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()
end = start + timeout
while not (time.time() >= end):
next_step = time.time() + interval
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))