[Zope3-checkins] SVN: Zope3/trunk/ Added ``index`` keyword argument to testbrowser's ``getLink()``

Stephan Richter srichter at cosmos.phy.tufts.edu
Wed Dec 6 04:16:30 EST 2006


Log message for revision 71429:
  Added ``index`` keyword argument to testbrowser's ``getLink()``
  method, so that later links with a match can be accessed
  too. Example: In the ZMI doing ``getLink('Folder')`` will give 
  you the "Buddy Folder" link and not the "Folder" link as expected. Use
  ``getLink('Folder', index=1)`` instead.
  
  

Changed:
  U   Zope3/trunk/doc/CHANGES.txt
  U   Zope3/trunk/src/zope/testbrowser/README.txt
  U   Zope3/trunk/src/zope/testbrowser/browser.py

-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt	2006-12-05 23:24:45 UTC (rev 71428)
+++ Zope3/trunk/doc/CHANGES.txt	2006-12-06 09:16:29 UTC (rev 71429)
@@ -10,6 +10,12 @@
 
     New features
 
+      - Added ``index`` keyword argument to testbrowser's ``getLink()``
+        method, so that later links with a match can be accessed
+        too. Example: In the ZMI doing ``getLink('Folder')`` will give you the
+        "Buddy Folder" link and not the "Folder" link as expected. Use
+        ``getLink('Folder', index=1)`` instead.
+
       - Added breadcrumbs to all types of objects visible through the
         code documentation browser.
 

Modified: Zope3/trunk/src/zope/testbrowser/README.txt
===================================================================
--- Zope3/trunk/src/zope/testbrowser/README.txt	2006-12-05 23:24:45 UTC (rev 71428)
+++ Zope3/trunk/src/zope/testbrowser/README.txt	2006-12-06 09:16:29 UTC (rev 71429)
@@ -209,6 +209,16 @@
     >>> browser.contents
     '...Message: <em>By Link Text with Normalization</em>...'
 
+When a link text matches more than one link, by default the first one is
+chosen. You can, however, specify the index of the link and thus retrieve a
+later matching link:
+
+    >>> browser.getLink('Link Text')
+    <Link text='Link Text' ...>
+
+    >>> browser.getLink('Link Text', index=1)
+    <Link text='Link Text with Whitespace Normalization (and parens)' ...>
+
 Note that clicking a link object after its browser page has expired will
 generate an error.
 

Modified: Zope3/trunk/src/zope/testbrowser/browser.py
===================================================================
--- Zope3/trunk/src/zope/testbrowser/browser.py	2006-12-05 23:24:45 UTC (rev 71428)
+++ Zope3/trunk/src/zope/testbrowser/browser.py	2006-12-06 09:16:29 UTC (rev 71429)
@@ -269,7 +269,7 @@
         """See zope.testbrowser.interfaces.IBrowser"""
         self.mech_browser.addheaders.append( (key, value) )
 
-    def getLink(self, text=None, url=None, id=None):
+    def getLink(self, text=None, url=None, id=None, index=0):
         """See zope.testbrowser.interfaces.IBrowser"""
         if id is not None:
             def predicate(link):
@@ -290,6 +290,7 @@
             else:
                 url_regex = None
             args = {'text_regex': text_regex, 'url_regex': url_regex}
+        args['nr'] = index
         return Link(self.mech_browser.find_link(**args), self)
 
     def _findByLabel(self, label, forms, include_subcontrols=False):



More information about the Zope3-Checkins mailing list