--- a/testing/marionette/harness/marionette_harness/marionette_test/testcases.py
+++ b/testing/marionette/harness/marionette_harness/marionette_test/testcases.py
@@ -335,18 +335,8 @@ class MarionetteTestCase(CommonTestCase)
# In the case no session is active (eg. the application was quit), start
# a new session for clean-up steps.
if not self.marionette.session:
self.marionette.start_session()
self.marionette.test_name = None
super(MarionetteTestCase, self).tearDown()
-
- def wait_for_condition(self, method, timeout=30):
- timeout = float(timeout) + time.time()
- while time.time() < timeout:
- value = method(self.marionette)
- if value:
- return value
- time.sleep(0.5)
- else:
- raise TimeoutException("wait_for_condition timed out")
--- a/testing/marionette/harness/marionette_harness/tests/unit/single_finger_functions.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/single_finger_functions.py
@@ -1,133 +1,133 @@
from __future__ import absolute_import
from marionette_driver.marionette import Actions
from marionette_driver.errors import TimeoutException
from marionette_driver.by import By
+from marionette_driver.wait import Wait
-def wait_for_condition_else_raise(marionette, wait_for_condition, expected, script):
- try:
- wait_for_condition(lambda m: expected in m.execute_script(script))
- except TimeoutException as e:
- raise TimeoutException("{0} got {1} instead of {2}".format(
- e.message, marionette.execute_script(script), expected))
+def wait_for_condition_else_raise(marionette, expected, script):
+ Wait(marionette, timeout=30).until(
+ lambda m: expected in m.execute_script(script),
+ message="got {0} instead of {1}".format(marionette.execute_script(script), expected),
+ )
-def press_release(marionette, times, wait_for_condition, expected):
+def press_release(marionette, times, expected):
testAction = marionette.absolute_url("testAction.html")
marionette.navigate(testAction)
action = Actions(marionette)
button = marionette.find_element(By.ID, "button1")
action.press(button).release()
# Insert wait between each press and release chain.
for _ in range(times-1):
action.wait(0.1)
action.press(button).release()
action.perform()
- wait_for_condition_else_raise(marionette, wait_for_condition, expected, "return document.getElementById('button1').innerHTML;")
+ wait_for_condition_else_raise(marionette, expected, "return document.getElementById('button1').innerHTML;")
-def move_element(marionette, wait_for_condition, expected1, expected2):
+def move_element(marionette, expected1, expected2):
testAction = marionette.absolute_url("testAction.html")
marionette.navigate(testAction)
ele = marionette.find_element(By.ID, "button1")
drop = marionette.find_element(By.ID, "button2")
action = Actions(marionette)
action.press(ele).move(drop).release()
action.perform()
- wait_for_condition_else_raise(marionette, wait_for_condition, expected1, "return document.getElementById('button1').innerHTML;")
- wait_for_condition_else_raise(marionette, wait_for_condition, expected2, "return document.getElementById('button2').innerHTML;")
+ wait_for_condition_else_raise(marionette, expected1, "return document.getElementById('button1').innerHTML;")
+ wait_for_condition_else_raise(marionette, expected2, "return document.getElementById('button2').innerHTML;")
-def move_element_offset(marionette, wait_for_condition, expected1, expected2):
+def move_element_offset(marionette, expected1, expected2):
testAction = marionette.absolute_url("testAction.html")
marionette.navigate(testAction)
ele = marionette.find_element(By.ID, "button1")
action = Actions(marionette)
action.press(ele).move_by_offset(0,150).move_by_offset(0, 150).release()
action.perform()
- wait_for_condition_else_raise(marionette, wait_for_condition, expected1, "return document.getElementById('button1').innerHTML;")
- wait_for_condition_else_raise(marionette, wait_for_condition, expected2, "return document.getElementById('button2').innerHTML;")
+ wait_for_condition_else_raise(marionette, expected1, "return document.getElementById('button1').innerHTML;")
+ wait_for_condition_else_raise(marionette, expected2, "return document.getElementById('button2').innerHTML;")
-def chain(marionette, wait_for_condition, expected1, expected2):
+def chain(marionette, expected1, expected2):
testAction = marionette.absolute_url("testAction.html")
marionette.navigate(testAction)
marionette.timeout.implicit = 15
action = Actions(marionette)
button1 = marionette.find_element(By.ID, "button1")
action.press(button1).perform()
button2 = marionette.find_element(By.ID, "delayed")
- wait_for_condition_else_raise(marionette, wait_for_condition, expected1, "return document.getElementById('button1').innerHTML;")
+ wait_for_condition_else_raise(marionette, expected1, "return document.getElementById('button1').innerHTML;")
action.move(button2).release().perform()
- wait_for_condition_else_raise(marionette, wait_for_condition, expected2, "return document.getElementById('delayed').innerHTML;")
+ wait_for_condition_else_raise(marionette, expected2, "return document.getElementById('delayed').innerHTML;")
-def chain_flick(marionette, wait_for_condition, expected1, expected2):
+def chain_flick(marionette, expected1, expected2):
testAction = marionette.absolute_url("testAction.html")
marionette.navigate(testAction)
button = marionette.find_element(By.ID, "button1")
action = Actions(marionette)
action.flick(button, 0, 0, 0, 200).perform()
- wait_for_condition_else_raise(marionette, wait_for_condition, expected1,"return document.getElementById('button1').innerHTML;")
- wait_for_condition_else_raise(marionette, wait_for_condition, expected2,"return document.getElementById('buttonFlick').innerHTML;")
+ wait_for_condition_else_raise(marionette, expected1,"return document.getElementById('button1').innerHTML;")
+ wait_for_condition_else_raise(marionette, expected2,"return document.getElementById('buttonFlick').innerHTML;")
-def wait(marionette, wait_for_condition, expected):
+def wait(marionette, expected):
testAction = marionette.absolute_url("testAction.html")
marionette.navigate(testAction)
action = Actions(marionette)
button = marionette.find_element(By.ID, "button1")
action.press(button).wait().release().perform()
- wait_for_condition_else_raise(marionette, wait_for_condition, expected, "return document.getElementById('button1').innerHTML;")
+ wait_for_condition_else_raise(marionette, expected, "return document.getElementById('button1').innerHTML;")
-def wait_with_value(marionette, wait_for_condition, expected):
+def wait_with_value(marionette, expected):
testAction = marionette.absolute_url("testAction.html")
marionette.navigate(testAction)
button = marionette.find_element(By.ID, "button1")
action = Actions(marionette)
action.press(button).wait(0.01).release()
action.perform()
- wait_for_condition_else_raise(marionette, wait_for_condition, expected, "return document.getElementById('button1').innerHTML;")
+ wait_for_condition_else_raise(marionette, expected, "return document.getElementById('button1').innerHTML;")
-def context_menu(marionette, wait_for_condition, expected1, expected2):
+def context_menu(marionette, expected1, expected2):
testAction = marionette.absolute_url("testAction.html")
marionette.navigate(testAction)
button = marionette.find_element(By.ID, "button1")
action = Actions(marionette)
action.press(button).wait(5).perform()
- wait_for_condition_else_raise(marionette, wait_for_condition, expected1, "return document.getElementById('button1').innerHTML;")
+ wait_for_condition_else_raise(marionette, expected1, "return document.getElementById('button1').innerHTML;")
action.release().perform()
- wait_for_condition_else_raise(marionette, wait_for_condition, expected2, "return document.getElementById('button1').innerHTML;")
+ wait_for_condition_else_raise(marionette, expected2, "return document.getElementById('button1').innerHTML;")
-def long_press_action(marionette, wait_for_condition, expected):
+def long_press_action(marionette, expected):
testAction = marionette.absolute_url("testAction.html")
marionette.navigate(testAction)
button = marionette.find_element(By.ID, "button1")
action = Actions(marionette)
action.long_press(button, 5).perform()
- wait_for_condition_else_raise(marionette, wait_for_condition, expected, "return document.getElementById('button1').innerHTML;")
+ wait_for_condition_else_raise(marionette, expected, "return document.getElementById('button1').innerHTML;")
-def long_press_on_xy_action(marionette, wait_for_condition, expected):
+def long_press_on_xy_action(marionette, expected):
testAction = marionette.absolute_url("testAction.html")
marionette.navigate(testAction)
html = marionette.find_element(By.TAG_NAME, "html")
button = marionette.find_element(By.ID, "button1")
action = Actions(marionette)
# Press the center of the button with respect to html.
x = button.rect['x'] + button.rect['width'] / 2.0
y = button.rect['y'] + button.rect['height'] / 2.0
action.long_press(html, 5, x, y).perform()
- wait_for_condition_else_raise(marionette, wait_for_condition, expected, "return document.getElementById('button1').innerHTML;")
+ wait_for_condition_else_raise(marionette, expected, "return document.getElementById('button1').innerHTML;")
-def single_tap(marionette, wait_for_condition, expected):
+def single_tap(marionette, expected):
testAction = marionette.absolute_url("testAction.html")
marionette.navigate(testAction)
button = marionette.find_element(By.ID, "button1")
action = Actions(marionette)
action.tap(button).perform()
- wait_for_condition_else_raise(marionette, wait_for_condition, expected, "return document.getElementById('button1').innerHTML;")
+ wait_for_condition_else_raise(marionette, expected, "return document.getElementById('button1').innerHTML;")
-def double_tap(marionette, wait_for_condition, expected):
+def double_tap(marionette, expected):
testAction = marionette.absolute_url("testAction.html")
marionette.navigate(testAction)
button = marionette.find_element(By.ID, "button1")
action = Actions(marionette)
action.double_tap(button).perform()
- wait_for_condition_else_raise(marionette, wait_for_condition, expected, "return document.getElementById('button1').innerHTML;")
+ wait_for_condition_else_raise(marionette, expected, "return document.getElementById('button1').innerHTML;")
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_legacy_mouse_action.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_legacy_mouse_action.py
@@ -6,16 +6,17 @@ from __future__ import absolute_import
import urllib
from marionette_driver.by import By
from marionette_driver.keys import Keys
from marionette_driver.marionette import Actions
from marionette_harness import MarionetteTestCase
+from marionette_driver.wait import Wait
def inline(doc):
return "data:text/html;charset=utf-8,{}".format(urllib.quote(doc))
class BaseLegacyMouseAction(MarionetteTestCase):
@@ -66,42 +67,52 @@ class TestLegacyMouseAction(BaseLegacyMo
def context_menu_state():
with self.marionette.using_context("chrome"):
cm_el = self.marionette.find_element(By.ID, "contentAreaContextMenu")
return cm_el.get_property("state")
self.assertEqual("closed", context_menu_state())
self.action.context_click(click_el).perform()
- self.wait_for_condition(lambda _: context_menu_state() == "open")
+ Wait(self.marionette).until(
+ lambda _: context_menu_state() == "open",
+ message="The context menu has not been opened",
+ )
with self.marionette.using_context("chrome"):
self.marionette.find_element(By.ID, "main-window").send_keys(Keys.ESCAPE)
- self.wait_for_condition(lambda _: context_menu_state() == "closed")
+ Wait(self.marionette).until(
+ lambda _: context_menu_state() == "closed",
+ message="The context menu has not been closed",
+ )
def test_middle_click_action(self):
test_html = self.marionette.absolute_url("clicks.html")
self.marionette.navigate(test_html)
self.marionette.find_element(By.ID, "addbuttonlistener").click()
el = self.marionette.find_element(By.ID, "showbutton")
self.action.middle_click(el).perform()
- self.wait_for_condition(lambda _: el.get_property("innerHTML") == "1")
+ Wait(self.marionette).until(
+ lambda _: el.get_property("innerHTML") == "1",
+ )
def test_chrome_click(self):
self.marionette.navigate("about:blank")
data_uri = "data:text/html,<html></html>"
with self.marionette.using_context("chrome"):
urlbar = self.marionette.find_element(By.ID, "urlbar")
urlbar.send_keys(data_uri)
go_button = self.marionette.execute_script("return gURLBar.goButton")
self.action.click(go_button).perform()
- self.wait_for_condition(lambda mn: mn.get_url() == data_uri)
+ Wait(self.marionette).until(
+ lambda mn: mn.get_url() == data_uri,
+ )
class TestChromeLegacyMouseAction(BaseLegacyMouseAction):
def setUp(self):
super(TestChromeLegacyMouseAction, self).setUp()
self.marionette.set_context("chrome")
@@ -125,14 +136,20 @@ class TestChromeLegacyMouseAction(BaseLe
def test_chrome_context_click_action(self):
def context_menu_state():
cm_el = self.marionette.find_element(By.ID, "tabContextMenu")
return cm_el.get_property("state")
currtab = self.marionette.execute_script("return gBrowser.selectedTab")
self.assertEqual("closed", context_menu_state())
self.action.context_click(currtab).perform()
- self.wait_for_condition(lambda _: context_menu_state() == "open")
+ Wait(self.marionette).until(
+ lambda _: context_menu_state() == "open",
+ message="The context menu has not been opened",
+ )
(self.marionette.find_element(By.ID, "main-window")
.send_keys(Keys.ESCAPE))
- self.wait_for_condition(lambda _: context_menu_state() == "closed")
+ Wait(self.marionette).until(
+ lambda _: context_menu_state() == "closed",
+ message="The context menu has not been closed",
+ )
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_modal_dialogs.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_modal_dialogs.py
@@ -72,42 +72,46 @@ class TestTabModalAlerts(BaseAlertTestCa
alert = self.marionette.switch_to_alert()
alert.dismiss()
def test_confirm_accept(self):
self.marionette.find_element(By.ID, "tab-modal-confirm").click()
self.wait_for_alert()
alert = self.marionette.switch_to_alert()
alert.accept()
- self.wait_for_condition(
- lambda mn: mn.find_element(By.ID, "confirm-result").text == "true")
+ Wait(self.marionette).until(
+ lambda mn: mn.find_element(By.ID, "confirm-result").text == "true",
+ )
def test_confirm_dismiss(self):
self.marionette.find_element(By.ID, "tab-modal-confirm").click()
self.wait_for_alert()
alert = self.marionette.switch_to_alert()
alert.dismiss()
- self.wait_for_condition(
- lambda mn: mn.find_element(By.ID, "confirm-result").text == "false")
+ Wait(self.marionette).until(
+ lambda mn: mn.find_element(By.ID, "confirm-result").text == "false",
+ )
def test_prompt_accept(self):
self.marionette.find_element(By.ID, "tab-modal-prompt").click()
self.wait_for_alert()
alert = self.marionette.switch_to_alert()
alert.accept()
- self.wait_for_condition(
- lambda mn: mn.find_element(By.ID, "prompt-result").text == "")
+ Wait(self.marionette).until(
+ lambda mn: mn.find_element(By.ID, "prompt-result").text == "",
+ message="Value of element 'prompt-result' is not empty")
def test_prompt_dismiss(self):
self.marionette.find_element(By.ID, "tab-modal-prompt").click()
self.wait_for_alert()
alert = self.marionette.switch_to_alert()
alert.dismiss()
- self.wait_for_condition(
- lambda mn: mn.find_element(By.ID, "prompt-result").text == "null")
+ Wait(self.marionette).until(
+ lambda mn: mn.find_element(By.ID, "prompt-result").text == "null",
+ message="Value of element 'prompt-result' is not null")
def test_alert_opened_before_session_starts(self):
self.marionette.find_element(By.ID, "tab-modal-alert").click()
self.wait_for_alert()
# Restart the session to ensure we still find the formerly left-open dialog.
self.marionette.delete_session()
self.marionette.start_session()
@@ -156,54 +160,60 @@ class TestTabModalAlerts(BaseAlertTestCa
alert.accept()
def test_set_text_accept(self):
self.marionette.find_element(By.ID, "tab-modal-prompt").click()
self.wait_for_alert()
alert = self.marionette.switch_to_alert()
alert.send_keys("Some text!")
alert.accept()
- self.wait_for_condition(
- lambda mn: mn.find_element(By.ID, "prompt-result").text == "Some text!")
+ Wait(self.marionette).until(
+ lambda mn: mn.find_element(By.ID, "prompt-result").text == "Some text!",
+ message="value of element 'prompt-result' is not 'Some text!'")
def test_set_text_dismiss(self):
self.marionette.find_element(By.ID, "tab-modal-prompt").click()
self.wait_for_alert()
alert = self.marionette.switch_to_alert()
alert.send_keys("Some text!")
alert.dismiss()
- self.wait_for_condition(
- lambda mn: mn.find_element(By.ID, "prompt-result").text == "null")
+ Wait(self.marionette).until(
+ lambda mn: mn.find_element(By.ID, "prompt-result").text == "null",
+ message="Value of element 'prompt-result' is not null")
def test_onbeforeunload_dismiss(self):
start_url = self.marionette.get_url()
self.marionette.find_element(By.ID, "onbeforeunload-handler").click()
- self.wait_for_condition(
+ Wait(self.marionette).until(
lambda mn: mn.execute_script("""
return window.onbeforeunload !== null;
- """))
+ """),
+ message="Handler for 'onbeforeunload' has not been set")
self.marionette.navigate("about:blank")
self.wait_for_alert()
alert = self.marionette.switch_to_alert()
self.assertTrue(alert.text.startswith("This page is asking you to confirm"))
alert.dismiss()
self.assertTrue(self.marionette.get_url().startswith(start_url))
def test_onbeforeunload_accept(self):
self.marionette.find_element(By.ID, "onbeforeunload-handler").click()
- self.wait_for_condition(
+ Wait(self.marionette).until(
lambda mn: mn.execute_script("""
return window.onbeforeunload !== null;
- """))
+ """),
+ message="Handler for 'onbeforeunload' has not been set")
self.marionette.navigate("about:blank")
self.wait_for_alert()
alert = self.marionette.switch_to_alert()
self.assertTrue(alert.text.startswith("This page is asking you to confirm"))
alert.accept()
- self.wait_for_condition(lambda mn: mn.get_url() == "about:blank")
+ Wait(self.marionette).until(
+ lambda mn: mn.get_url() == "about:blank",
+ message="The expected page 'about:blank' has not been loaded")
def test_unrelated_command_when_alert_present(self):
self.marionette.find_element(By.ID, "tab-modal-alert").click()
self.wait_for_alert()
with self.assertRaises(errors.UnexpectedAlertOpen):
self.marionette.find_element(By.ID, "click-result")
def test_modal_is_dismissed_after_unexpected_alert(self):
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_single_finger_desktop.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_single_finger_desktop.py
@@ -65,36 +65,36 @@ prefs.setBoolPref("ui.click_hold_context
let prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
prefs.setIntPref("ui.click_hold_context_menus.delay", arguments[0]);
""", [self.wait_time])
self.marionette.set_context("content")
super(MarionetteTestCase, self).tearDown()
def test_press_release(self):
- press_release(self.marionette, 1, self.wait_for_condition, "button1-mousemove-mousedown-mouseup-click")
+ press_release(self.marionette, 1, "button1-mousemove-mousedown-mouseup-click")
def test_press_release_twice(self):
- press_release(self.marionette, 2, self.wait_for_condition, "button1-mousemove-mousedown-mouseup-click-mousemove-mousedown-mouseup-click")
+ press_release(self.marionette, 2, "button1-mousemove-mousedown-mouseup-click-mousemove-mousedown-mouseup-click")
def test_move_element(self):
- move_element(self.marionette, self.wait_for_condition, "button1-mousemove-mousedown", "button2-mousemove-mouseup")
+ move_element(self.marionette, "button1-mousemove-mousedown", "button2-mousemove-mouseup")
def test_move_by_offset(self):
- move_element_offset(self.marionette, self.wait_for_condition, "button1-mousemove-mousedown", "button2-mousemove-mouseup")
+ move_element_offset(self.marionette, "button1-mousemove-mousedown", "button2-mousemove-mouseup")
def test_wait(self):
- wait(self.marionette, self.wait_for_condition, "button1-mousemove-mousedown-mouseup-click")
+ wait(self.marionette, "button1-mousemove-mousedown-mouseup-click")
def test_wait_with_value(self):
- wait_with_value(self.marionette, self.wait_for_condition, "button1-mousemove-mousedown-mouseup-click")
+ wait_with_value(self.marionette, "button1-mousemove-mousedown-mouseup-click")
@skip("Bug 1191066")
def test_context_menu(self):
- context_menu(self.marionette, self.wait_for_condition,
+ context_menu(self.marionette,
"button1-mousemove-mousedown-contextmenu",
"button1-mousemove-mousedown-contextmenu-mouseup-click")
@skip("Bug 1191066")
def test_long_press_action(self):
long_press_action(self.marionette, self.wait_for_condition,
"button1-mousemove-mousedown-contextmenu-mouseup-click")
@@ -108,18 +108,18 @@ prefs.setIntPref("ui.click_hold_context_
testAction = self.marionette.absolute_url("testAction.html")
self.marionette.navigate(testAction)
button = self.marionette.find_element(By.ID, "button1Copy")
action = Actions(self.marionette)
action.press(button).long_press(button, 5)
self.assertRaises(MarionetteException, action.perform)
def test_chain(self):
- chain(self.marionette, self.wait_for_condition, "button1-mousemove-mousedown", "delayed-mousemove-mouseup")
+ chain(self.marionette, "button1-mousemove-mousedown", "delayed-mousemove-mouseup")
def test_chain_flick(self):
- chain_flick(self.marionette, self.wait_for_condition, "button1-mousemove-mousedown-mousemove", "buttonFlick-mousemove-mouseup")
+ chain_flick(self.marionette, "button1-mousemove-mousedown-mousemove", "buttonFlick-mousemove-mouseup")
def test_single_tap(self):
- single_tap(self.marionette, self.wait_for_condition, "button1-mousemove-mousedown-mouseup-click")
+ single_tap(self.marionette, "button1-mousemove-mousedown-mouseup-click")
def test_double_tap(self):
- double_tap(self.marionette, self.wait_for_condition, "button1-mousemove-mousedown-mouseup-click-mousemove-mousedown-mouseup-click")
+ double_tap(self.marionette, "button1-mousemove-mousedown-mouseup-click-mousemove-mousedown-mouseup-click")