Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

zope.testbrowser supports `is_text_present` #210

Merged
merged 1 commit into from

3 participants

Michael Edwards Francisco Souza Hugo Lopes Tavares
Michael Edwards

With is_text_present promoted to the canonical way to grab text content on a page, I updated zope.testbrowser to be consistent.

Francisco Souza fsouza merged commit ff40923 into from
Francisco Souza
Owner

Thank you :-)

Hugo Lopes Tavares
Owner

This pull request seems to introduce a bug in splinter. There is no test running for this change as I can see...

ZopeTestBrowserDriverTest inherits from BaseBrowserTests, and at the moment IsTextPresentTest mixin isn't there.

I just tried here and it crashes. The exceptions caught are not enough. I adapting it to run the proper tests.

Hugo Lopes Tavares
Owner

Did you guys realize this patch imports from selenium.common.exceptions? It has nothing to do with zope.testbrowser and ElementList.
That try/except is wrong. It should catch splinter.exceptions.ElementDoesNotExist, right?

Hugo Lopes Tavares hltbra referenced this pull request from a commit
Hugo Lopes Tavares hltbra Fix try/except of zope.testbrowser's `is_text_present` and enable tes…
…ts to that feature. Refs #210
baed13d
Michael Edwards

Thanks Hugo, that was a serious herp derp moment on my part. I've been spending a lot of time working with Browser.driver more directly so I get mixed up when I come back to splinter-land. I should know better and not ned more proof that manual testing is never enough!

Hugo Lopes Tavares
Owner

That's ok, @medwards. It is good that you implemented it, and if you did not do nobody would have done. Thanks!

PS.: Shit happens. Sometimes I am not so confident with code I've written, and I use to remove the code, do not touch the tests, run the tests, and if nothing breaks, it means I did not setup the test correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 21, 2013
  1. Michael Edwards
This page is out of date. Refresh to see the latest.
Showing with 34 additions and 0 deletions.
  1. +34 −0 splinter/driver/zopetestbrowser.py
34 splinter/driver/zopetestbrowser.py
View
@@ -9,6 +9,7 @@
from lxml.cssselect import CSSSelector
from zope.testbrowser.browser import Browser
+from selenium.common.exceptions import NoSuchElementException
from splinter.element_list import ElementList
from splinter.driver import DriverAPI, ElementAPI
from splinter.cookie_manager import CookieManagerAPI
@@ -16,6 +17,7 @@
import mimetypes
import lxml.html
import mechanize
+import time
class CookieManager(CookieManagerAPI):
@@ -206,6 +208,38 @@ def _find_links_by_xpath(self, xpath):
def select(self, name, value):
self.find_by_name(name).first._control.value = [value]
+ def is_text_present(self, text, wait_time=None):
+ wait_time = wait_time or 2
+ end_time = time.time() + wait_time
+
+ while time.time() < end_time:
+ if self._is_text_present(text):
+ return True
+ return False
+
+ def _is_text_present(self, text):
+ try:
+ body = self.find_by_tag('body').first
+ body.text.index(text)
+ return True
+ except ValueError:
+ pass
+ except NoSuchElementException:
+ # This exception will be thrown if the body tag isn't present
+ # This has occasionally been observed. Assume that the
+ # page isn't fully loaded yet
+ pass
+ return False
+
+ def is_text_not_present(self, text, wait_time=None):
+ wait_time = wait_time or 2
+ end_time = time.time() + wait_time
+
+ while time.time() < end_time:
+ if not self._is_text_present(text):
+ return True
+ return False
+
def _element_is_link(self, element):
return element.tag == 'a'
Something went wrong with that request. Please try again.