Remote control websites with zope.testbrowser
It's one of those small little things that I didn't realize eventhough (at least in hindsight) it should have been perfectly obvious all along... Here it is... *drumroll*: you can use zope.testbrowser's Browser API also to test 'remote' , i.e. non-Zope sites. Here's an example:
from unittest import TestSuite, main
from Testing.ZopeTestCase import ZopeDocTestSuite
def test_remote_browsing():
"""
By importing directly from zope.testbrowser.browser we can use
the Browser API also for testing remote (non-Zope) sites:
>>> from zope.testbrowser.browser import Browser
>>> browser = Browser()
>>> browser.open('http://en.wikipedia.org/wiki/Monty_Python')
>>> browser.url
'http://en.wikipedia.org/wiki/Monty_Python'
>>> browser.contents
'...Dead Parrot...'
"""
def test_suite():
return ZopeDocTestSuite()
if __name__ == '__main__':
main(defaultTest='test_suite')
Admittedly, I haven't got a specific use case for this at the moment, but the Browser API's many useful convenience methods (such as
Once again, "tip o' the hat" to witsch – who still needs to get himself a blog, dammit ;-)
Update: Martijn is right: credit, where credit is due: it's actually zope.testbrowser (with mechanize) which provides the relevant functionality and not ZopeTestCase.
getControl) should allow for some pretty nifty python-scripted 'remote control'-power over any site... i.e. not to use the API for testing but rather for scripting...Once again, "tip o' the hat" to witsch – who still needs to get himself a blog, dammit ;-)
Update: Martijn is right: credit, where credit is due: it's actually zope.testbrowser (with mechanize) which provides the relevant functionality and not ZopeTestCase.
