[Zope3-checkins] SVN: Zope3/branches/testbrowser-integration/src/zope/testbrowser/ Work on zope.testbrowser:

Benji York benji at zope.com
Sat Jul 30 11:23:46 EDT 2005


Log message for revision 37601:
  Work on zope.testbrowser:
   - browser.click now accepts strings to do substring searches, and compiled
     regular expression objects to do regex searches for "text" and "url"
     parameters
  

Changed:
  U   Zope3/branches/testbrowser-integration/src/zope/testbrowser/README.txt
  U   Zope3/branches/testbrowser-integration/src/zope/testbrowser/browser.py

-=-
Modified: Zope3/branches/testbrowser-integration/src/zope/testbrowser/README.txt
===================================================================
--- Zope3/branches/testbrowser-integration/src/zope/testbrowser/README.txt	2005-07-30 15:14:36 UTC (rev 37600)
+++ Zope3/branches/testbrowser-integration/src/zope/testbrowser/README.txt	2005-07-30 15:23:46 UTC (rev 37601)
@@ -138,7 +138,7 @@
     >>> browser.contents
     '...<a href="navigate.html?message=By+URL">Using the URL</a>...'
 
-    >>> browser.click(url='\?message=By\+URL')
+    >>> browser.click(url='?message=By+URL')
     >>> browser.url
     'http://localhost/@@/testbrowser/navigate.html?message=By+URL'
     >>> browser.contents

Modified: Zope3/branches/testbrowser-integration/src/zope/testbrowser/browser.py
===================================================================
--- Zope3/branches/testbrowser-integration/src/zope/testbrowser/browser.py	2005-07-30 15:14:36 UTC (rev 37600)
+++ Zope3/branches/testbrowser-integration/src/zope/testbrowser/browser.py	2005-07-30 15:23:46 UTC (rev 37601)
@@ -22,6 +22,7 @@
 
 from zope.testbrowser import interfaces
 
+RegexType = type(re.compile(''))
 
 class Browser(object):
     """A web user agent."""
@@ -128,20 +129,25 @@
             self._changed()
             return
 
-        # if we get here, we didn't find a control to click, so we'll look for
-        # a regular link
+        # If we get here, we didn't find a control to click, so we'll look for
+        # a regular link.
 
         if id is not None:
             def predicate(link):
                 return dict(link.attrs).get('id') == id
             self.mech_browser.follow_link(predicate=predicate)
         else:
-            if text is not None:
-                text_regex = re.compile(text)
+            if isinstance(text, RegexType):
+                text_regex = text
+            elif text is not None:
+                text_regex = re.compile(re.escape(text), re.DOTALL)
             else:
                 text_regex = None
-            if url is not None:
-                url_regex = re.compile(url)
+
+            if isinstance(url, RegexType):
+                url_regex = url
+            elif url is not None:
+                url_regex = re.compile(re.escape(url), re.DOTALL)
             else:
                 url_regex = None
 
@@ -161,7 +167,7 @@
             if form is None or control_form == form:
                 if (((id is not None and control.id == id)
                 or (name is not None and control.name == name)
-                or (text is not None and re.search(text, str(control.value)))
+                or (text is not None and text in str(control.value))
                 ) and (type is None or control.type == type)):
                     self.mech_browser.form = control_form
                     return control_form, control



More information about the Zope3-Checkins mailing list