Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions robotpageobjects/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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__")
Expand Down
25 changes: 18 additions & 7 deletions tests/scenarios/test_wait_until_not_visible.py
Original file line number Diff line number Diff line change
@@ -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__':
Expand Down