[Zope3-checkins]
SVN: Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/
Finished up controls tests and make sure image input controls are
Stephan Richter
srichter at cosmos.phy.tufts.edu
Wed Jul 27 19:27:16 EDT 2005
Log message for revision 37513:
Finished up controls tests and make sure image input controls are
recognized as submittable buttons and made sure that the coords are sent
correctly.
Changed:
U Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/README.txt
U Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/browser.py
U Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/ftests/controls.html
U Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/ftests/testdoc.py
-=-
Modified: Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/README.txt
===================================================================
--- Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/README.txt 2005-07-27 23:23:43 UTC (rev 37512)
+++ Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/README.txt 2005-07-27 23:27:15 UTC (rev 37513)
@@ -11,9 +11,9 @@
The browser can `open` web pages:
- >>> browser.open('http://localhost/@@/testbrowser/simple.html')
- >>> browser.url
- 'http://localhost/@@/testbrowser/simple.html'
+ >>> browser.open('http://localhost/@@/testbrowser/simple.html')
+ >>> browser.url
+ 'http://localhost/@@/testbrowser/simple.html'
Page Contents
@@ -30,6 +30,7 @@
<h1>Simple Page</h1>
</body>
</html>
+ <BLANKLINE>
Making assertions about page contents is easy.
@@ -107,6 +108,7 @@
Content-Type: text/html;charset=utf-8
X-Content-Type-Warning: guessed from content
X-Powered-By: Zope (www.zope.org), Python (www.python.org)
+ <BLANKLINE>
Or as a mapping:
@@ -300,7 +302,14 @@
>>> browser.controls['password-value']
'pass now'
+If we request a control that doesn't exist, an exception is raised.
+ >>> browser.controls['does_not_exist']
+ Traceback (most recent call last):
+ ...
+ KeyError: 'does_not_exist'
+
+
Control Objects
~~~~~~~~~~~~~~~
@@ -524,53 +533,94 @@
>>> ctrl.options
['1', '2', '3']
+ - Image Control
-Forms
------
+ >>> ctrl = browser.getControl('image-value')
+ >>> ctrl
+ Control(name='image-value', type='image')
+ >>> ctrl.value
+ ''
+ >>> ctrl.disabled
+ False
+ >>> ctrl.readonly
+ False
+ >>> ctrl.multiple
+ >>> ctrl.options
+ Traceback (most recent call last):
+ ...
+ AttributeError: options
- >>> browser.open('http://localhost/++etc++site/default/RootErrorReportingUtility/@@configure.html')
+ - Submit Control
+ >>> ctrl = browser.getControl('submit-value')
+ >>> ctrl
+ Control(name='submit-value', type='submit')
+ >>> ctrl.value
+ 'Submit'
+ >>> ctrl.disabled
+ False
+ >>> ctrl.readonly
+ True
+ >>> ctrl.multiple
+ >>> ctrl.options
+ Traceback (most recent call last):
+ ...
+ AttributeError: options
-The current page has a form on it, let's look at some of the controls:
- >>> browser.controls['keep_entries']
- '20'
- >>> browser.controls['copy_to_zlog']
- False
+Using Submitting Controls
+~~~~~~~~~~~~~~~~~~~~~~~~~
-If we request a control that doesn't exist, an exception is raised.
+Both, the submit and image type, should be clickable and submit the form:
- >>> browser.controls['does_not_exist']
- Traceback (most recent call last):
+ >>> browser.controls['text-value'] = 'Other Text'
+ >>> browser.click('Submit')
+ >>> print browser.contents
+ <html>
...
- KeyError: 'does_not_exist'
+ <em>Other Text</em>
+ <input type="text" name="text-value" value="Some Text" />
+ ...
+ <em>Submit</em>
+ <input type="submit" name="submit-value" value="Submit" />
+ ...
+ </html>
-We want to change some of the form values and submit.
+And also with the image value:
- >>> browser.controls['keep_entries'] = '40'
- >>> browser.controls['copy_to_zlog'] = True
- >>> browser.click('Save Changes')
+ >>> browser.open('http://localhost/@@/testbrowser/controls.html')
+ >>> browser.controls['text-value'] = 'Other Text'
+ >>> browser.click(name='image-value')
+ >>> print browser.contents
+ <html>
+ ...
+ <em>Other Text</em>
+ <input type="text" name="text-value" value="Some Text" />
+ ...
+ <em>1</em>
+ <em>1</em>
+ <input type="image" name="image-value" src="zope3logo.gif" />
+ ...
+ </html>
-Are our changes reflected on the resulting page?
+But when sending an image, you can also specify the coordinate you clicked:
- >>> browser.controls['keep_entries']
- '40'
- >>> browser.controls['copy_to_zlog']
- True
+ >>> browser.open('http://localhost/@@/testbrowser/controls.html')
+ >>> browser.click(name='image-value', coord=(50,25))
+ >>> print browser.contents
+ <html>
+ ...
+ <em>50</em>
+ <em>25</em>
+ <input type="image" name="image-value" src="zope3logo.gif" />
+ ...
+ </html>
-The `controls` object also has an `update()` method similar to that of
-a dictionary:
- >>> browser.controls.update(dict(keep_entries='30', copy_to_zlog=False))
- >>> browser.click('Save Changes')
- >>> browser.controls['keep_entries']
- '30'
- >>> browser.controls['copy_to_zlog']
- False
+Forms
+-----
-Finding Specific Forms
-----------------------
Because pages can have multiple forms with like-named controls, it is sometimes
neccesary to access forms by name or id. The browser's `forms` attribute can
Modified: Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/browser.py
===================================================================
--- Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/browser.py 2005-07-27 23:23:43 UTC (rev 37512)
+++ Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/browser.py 2005-07-27 23:27:15 UTC (rev 37513)
@@ -118,7 +118,11 @@
def click(self, text=None, url=None, id=None, name=None, coord=(1,1)):
"""See zope.app.testing.testbrowser.interfaces.IBrowser"""
+ # Determine whether the click is a form submit and click the submit
+ # button if this is the case.
form, control = self._findControl(text, id, name, type='submit')
+ if control is None:
+ form, control = self._findControl(text, id, name, type='image')
if control is not None:
self._clickSubmit(form, control, coord)
self._changed()
Modified: Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/ftests/controls.html
===================================================================
--- Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/ftests/controls.html 2005-07-27 23:23:43 UTC (rev 37512)
+++ Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/ftests/controls.html 2005-07-27 23:27:15 UTC (rev 37513)
@@ -68,8 +68,15 @@
<radio name="radio-value" value="2" selected="selected" />
<radio name="radio-value" value="3" />
- <input type="image" name="image" src="zope3logo.gif" />
- <input type="submit" name="submit" value="Submit" />
+ <em tal:condition="request/image-value.x|nothing"
+ tal:content="request/image-value.x" />
+ <em tal:condition="request/image-value.y|nothing"
+ tal:content="request/image-value.y" />
+ <input type="image" name="image-value" src="zope3logo.gif" />
+
+ <em tal:condition="request/submit-value|nothing"
+ tal:content="request/submit-value" />
+ <input type="submit" name="submit-value" value="Submit" />
</form>
</body>
Modified: Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/ftests/testdoc.py
===================================================================
--- Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/ftests/testdoc.py 2005-07-27 23:23:43 UTC (rev 37512)
+++ Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/ftests/testdoc.py 2005-07-27 23:27:15 UTC (rev 37513)
@@ -22,8 +22,9 @@
def test_suite():
- return FunctionalDocFileSuite('../README.txt',
- optionflags=doctest.NORMALIZE_WHITESPACE+doctest.ELLIPSIS)
+ return FunctionalDocFileSuite(
+ '../README.txt',
+ optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS)
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
More information about the Zope3-Checkins
mailing list