Skip to content

Commit

Permalink
DanielWagnerHall: Always try to evaluate a wait at least once
Browse files Browse the repository at this point in the history
r15891
  • Loading branch information
illicitonion committed Feb 15, 2012
1 parent 944dd71 commit 05b2b63
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 7 additions & 3 deletions py/selenium/webdriver/support/wait.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,30 @@ def until(self, method):
"""Calls the method provided with the driver as an argument until the \
return value is not False."""
end_time = time.time() + self._timeout
while(time.time() < end_time):
while(True):
try:
value = method(self._driver)
if value:
return value
except NoSuchElementException:
pass
time.sleep(self._poll)
if(time.time() > end_time):
break
raise TimeoutException()

def until_not(self, method):
"""Calls the method provided with the driver as an argument until the \
return value is False."""
end_time = time.time() + self._timeout
while(time.time() < end_time):
while(True):
try:
value = method(self._driver)
if value:
pass
except NoSuchElementException:
return True
time.sleep(self._poll)
raise TimeoutException()
if(time.time() > end_time):
break
raise TimeoutException()
6 changes: 6 additions & 0 deletions py/test/selenium/webdriver/support/webdriverwait_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ def testShouldWaitOnlyAsLongAsTimeoutSpecifiedWhenImplicitWaitsAreSet(self):
finally:
self.driver.implicitly_wait(0)

def testShouldWaitAtLeastOnce(self):
self._loadPage("simpleTest")
elements_exists = lambda driver: driver.find_elements_by_tag_name('h1')
elements = WebDriverWait(self.driver, 0).until(elements_exists)
self.assertTrue(len(elements) >= 1)

def _pageURL(self, name):
return "http://localhost:%d/%s.html" % (self.webserver.port, name)

Expand Down

0 comments on commit 05b2b63

Please sign in to comment.