Bug 1353895 - Add wait with timeout to test click with navigation; r?jgraham
MozReview-Commit-ID: 1sV2cfXitaB
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -67208,16 +67208,21 @@
{}
]
],
"webdriver/tests/support/merge_dictionaries.py": [
[
{}
]
],
+ "webdriver/tests/support/wait.py": [
+ [
+ {}
+ ]
+ ],
"webgl/OWNERS": [
[
{}
]
],
"webgl/common.js": [
[
{}
@@ -220603,17 +220608,17 @@
"ebdbe326fd2fc53a3522b846505808496407b5b8",
"support"
],
"webdriver/tests/actions/key.py": [
"69542dc107d881bf18dfff3203bfd7a9ec31b4ad",
"wdspec"
],
"webdriver/tests/actions/mouse.py": [
- "fa12c8c7c4883604d221db8cd6b366a5f70ff185",
+ "51ba095d3d754e30154c20b2910830c6d3e3410c",
"wdspec"
],
"webdriver/tests/actions/sequence.py": [
"6a90971de07950c74e54312fc4429074ea1bed21",
"wdspec"
],
"webdriver/tests/actions/special_keys.py": [
"3b10143dea60567f30b4ab6c544e005d02f31fc3",
@@ -220670,16 +220675,20 @@
"webdriver/tests/support/inline.py": [
"bc85126e5637145e81f27d037f3a9090747130c8",
"support"
],
"webdriver/tests/support/merge_dictionaries.py": [
"84a6d3c6f8f4afded0f21264bbaeebec38a7f827",
"support"
],
+ "webdriver/tests/support/wait.py": [
+ "a4b0c9c340ea7055139d9fcab3246ee836d6a441",
+ "support"
+ ],
"webdriver/tests/window_maximizing.py": [
"ba6b9109f5baaf6eb300a3f89f984753e9d5adb9",
"wdspec"
],
"webgl/OWNERS": [
"f8e0703fe2cc88edd21ef2c94fcb2e1a8889f5ae",
"support"
],
--- a/testing/web-platform/tests/webdriver/tests/actions/mouse.py
+++ b/testing/web-platform/tests/webdriver/tests/actions/mouse.py
@@ -1,12 +1,13 @@
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):
content = "<a href=\"{}\" id=\"link\">destination</a>".format(dest)
return inline(content)
def get_center(rect):
@@ -66,25 +67,27 @@ def test_click_element_center(session, t
def test_click_navigation(session, url):
destination = url("/webdriver/tests/actions/support/test_actions_wdspec.html")
start = link_doc(destination)
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])
@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):
drag_target = session.find.css("#dragTarget", all=False)
initial_rect = drag_target.rect
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/tests/support/wait.py
@@ -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))