зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1353895 - Add wait with timeout to test click with navigation; r=jgraham
MozReview-Commit-ID: 1sV2cfXitaB --HG-- extra : rebase_source : 532d43dc0c57b3e3fa3caed24c64c49255ae1181
This commit is contained in:
Родитель
7b10e7daf9
Коммит
62bf7d3e0f
|
@ -67213,6 +67213,11 @@
|
|||
{}
|
||||
]
|
||||
],
|
||||
"webdriver/tests/support/wait.py": [
|
||||
[
|
||||
{}
|
||||
]
|
||||
],
|
||||
"webgl/OWNERS": [
|
||||
[
|
||||
{}
|
||||
|
@ -220608,7 +220613,7 @@
|
|||
"wdspec"
|
||||
],
|
||||
"webdriver/tests/actions/mouse.py": [
|
||||
"fa12c8c7c4883604d221db8cd6b366a5f70ff185",
|
||||
"51ba095d3d754e30154c20b2910830c6d3e3410c",
|
||||
"wdspec"
|
||||
],
|
||||
"webdriver/tests/actions/sequence.py": [
|
||||
|
@ -220675,6 +220680,10 @@
|
|||
"84a6d3c6f8f4afded0f21264bbaeebec38a7f827",
|
||||
"support"
|
||||
],
|
||||
"webdriver/tests/support/wait.py": [
|
||||
"a4b0c9c340ea7055139d9fcab3246ee836d6a441",
|
||||
"support"
|
||||
],
|
||||
"webdriver/tests/window_maximizing.py": [
|
||||
"ba6b9109f5baaf6eb300a3f89f984753e9d5adb9",
|
||||
"wdspec"
|
||||
|
|
|
@ -2,6 +2,7 @@ import pytest
|
|||
|
||||
from tests.support.inline import inline
|
||||
from tests.actions.support.refine import get_events, filter_dict
|
||||
from tests.support.wait import wait
|
||||
|
||||
|
||||
def link_doc(dest):
|
||||
|
@ -71,15 +72,17 @@ def test_click_navigation(session, url):
|
|||
def click(link):
|
||||
mouse_chain = session.actions.sequence(
|
||||
"pointer", "pointer_id", {"pointerType": "mouse"})
|
||||
mouse_chain.click(element=link).pause(300).perform()
|
||||
mouse_chain.click(element=link).perform()
|
||||
|
||||
session.url = start
|
||||
error_message = "Did not navigate to %s" % destination
|
||||
|
||||
click(session.find.css("#link", all=False))
|
||||
assert session.url == destination
|
||||
wait(session, lambda s: s.url == destination, error_message)
|
||||
# repeat steps to check behaviour after document unload
|
||||
session.url = start
|
||||
click(session.find.css("#link", all=False))
|
||||
assert session.url == destination
|
||||
wait(session, lambda s: s.url == destination, error_message)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("drag_duration", [0, 300, 800])
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
import time
|
||||
|
||||
class TimeoutException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def wait(session, condition, message, interval=0.1, timeout=5):
|
||||
""" 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
|
||||
"""
|
||||
|
||||
start = time.time()
|
||||
end = start + timeout
|
||||
|
||||
while not (time.time() >= end):
|
||||
next_step = time.time() + interval
|
||||
success = condition(session)
|
||||
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))
|
Загрузка…
Ссылка в новой задаче