diff --git a/robotpageobjects/base.py b/robotpageobjects/base.py index 1b2c4fc..2f83dbe 100755 --- a/robotpageobjects/base.py +++ b/robotpageobjects/base.py @@ -867,16 +867,18 @@ def check_visibility(): return error or "Element locator '%s' was still matched after %s" % (locator, self._format_timeout(timeout)) self._wait_until_no_error(timeout, check_visibility) - def wait_for(self, condition): + def wait_for(self, condition, timeout=None, message=''): """ Waits for a condition defined by the passed function to become True. :param condition: The condition to wait for :type condition: callable + :param timeout: How long to wait for the condition, defaults to the selenium implicit wait + :type condition: number + :param message: Message to show if the wait times out + :type condition: string :returns: None """ - timeout = 10 - wait = WebDriverWait(self.get_current_browser(), - timeout) #TODO: move to default config, allow parameter to this function too + wait = WebDriverWait(self.get_current_browser(), timeout or self.selenium_implicit_wait) def wait_fnc(driver): try: @@ -886,7 +888,7 @@ def wait_fnc(driver): else: return ret - wait.until(wait_fnc) + wait.until(wait_fnc, message) return self @robot_alias("get_hash_on__name__") diff --git a/tests/scenarios/test_wait_until_not_visible.py b/tests/scenarios/test_wait_until_not_visible.py index d2c89fb..ee33f34 100755 --- a/tests/scenarios/test_wait_until_not_visible.py +++ b/tests/scenarios/test_wait_until_not_visible.py @@ -1,27 +1,38 @@ import unittest from po import selectors_page -from robotpageobjects import base -import time class WaitUntilNotVisibleTestCase(unittest.TestCase): - def test_wait_until_element_not_visible(self): + def setUp(self): self.p = selectors_page.Page() self.p.open() + + def test_wait_until_element_not_visible(self): self.p.click_element("remove-button") self.p.wait_until_element_is_not_visible("para-to-be-removed") self.p.page_should_not_contain_element("para-to-be-removed") - self.p.close() + + def test_wait_for_element_not_visible(self): + self.p.click_element("remove-button") + self.p.wait_for(lambda: not self.p.is_visible("para-to-be-removed")) + self.p.page_should_not_contain_element("para-to-be-removed") def test_wait_until_element_not_visible_throws_exception(self): try: - self.p = selectors_page.Page() - self.p.open() self.p.click_element("delayed-content-button") - self.p.wait_until_element_is_not_visible("para-to-be-removed",8) + self.p.wait_until_element_is_not_visible("para-to-be-removed", 8) except Exception, e: self.assertTrue(isinstance(e, AssertionError)) self.assertIn("still matched after", e.message) + + def test_wait_for_element_not_visible_throws_exception(self): + try: + self.p.click_element("delayed-content-button") + self.p.wait_for(lambda: not self.p.is_visible("para-to-be-removed"), 8, 'Element did not disappear') + except Exception, e: + self.assertIn("Element did not disappear", e.msg) + + def tearDown(self): self.p.close() if __name__ == '__main__':