Package: zope.testbrowser
zope.testbrowserprovides an easy-to-use programmable web browser
with special focus on testing.  It is used in Zope, but it’s not Zope
specific at all.  For instance, it can be used to test or otherwise
interact with any web site.Documentation is available at:https://zopetestbrowser.readthedocs.orgCHANGES6.0 (2023-03-27)Drop support for Python 2.7, 3.5, 3.6.Drop support for deprecatedpython setup.py test.Add support for Python 3.11.Do not break inmechReprwhen using<inputtype="date">.5.6.1 (2022-01-21)Ensure all objects have consistent resolution orders.5.6.0 (2022-01-21)Add support for Python 3.9 and 3.10.5.5.1 (2019-11-12)Stop sending aRefererheader whenbrowser.openorbrowser.postis called directly.  Seeissue 87.Add error checking to the setters forListControl.displayValueandCheckboxListControl.displayValue: in line with the oldmechanize-based implementation, these will now raiseItemNotFoundErrorif any of the given values are not found, orItemCountErroron trying to set more than one value on a single-valued
control.  Seeissue 44.Fix AttributeError inadd_filewhen trying to add to a control which is
not a file upload.5.5.0 (2019-11-11)Fix a bug wherebrowser.goBack()did not invalidate caches, so
subsequent queries could use data from the wrong response.  Seeissue 83.Support telling the browser not to follow redirects by settingBrowser.follow_redirectsto False.  Seeissue 79.5.4.0 (2019-11-01)Fix a bug where browser.reload() would not follow redirects or raise
exceptions for bad HTTP statuses.  Seeissue 75.Add Python 3.8 support.  Seeissue 80.5.3.3 (2019-07-02)Fix a bug where clicking the selected radio button would unselect it.  Seeissue 68.Fix another incompatibility with BeautifulSoup4 >= 4.7 that could result
in a SyntaxError from browser.getLink().  Seeissue 61.5.3.2 (2019-02-06)Fix an incompatibility with BeautifulSoup4 >= 4.7 that could result
in a SyntaxError from browser.getControl().  Seeissue 61.Fix a bug where you couldn’t set a cookie expiration date when your locale
was not English.  Seeissue 65.Fix narrative doctests that started failing on January 1st, 2019 due to a
hardcoded “future” date.  Seeissue 62.5.3.1 (2018-10-23)Fix aDeprecationWarningon Python 3. Seeissue 51.5.3.0 (2018-10-10)Add support for Python 3.7.Drop support for Python 3.3 and 3.4.Drop support for pystone as Python 3.7 dropped pystone. SoBrowser.lastRequestPystonesno longer exists. Rename.browser.PystoneTimerto.browser.Timer.FixmechReprof CheckboxListControl to always return a native str.
(https://github.com/zopefoundation/zope.testbrowser/pull/46).AddmechReprto input fields having the typeemail.
(https://github.com/zopefoundation/zope.testbrowser/pull/47).5.2.4 (2017-11-24)Fix form submit with GET method if the form action contains a query string
(https://github.com/zopefoundation/zope.testbrowser/pull/42).Restore ignoring hidden elements when searching by label
(https://github.com/zopefoundation/zope.testbrowser/pull/41).5.2.3 (2017-10-18)FixmechRepron controls to always return a native str
(https://github.com/zopefoundation/zope.testbrowser/issues/38).5.2.2 (2017-10-10)Restore raising of AttributeError when trying to set value of a
read only control.Fix selecting radio and select control options by index
(https://github.com/zopefoundation/zope.testbrowser/issues/31).5.2.1 (2017-09-01)Exclude version 2.0.27 ofWebTestfrom allowed versions as it breaks some
tests.Adapt tests to version 2.0.28 ofWebTestbut keeping compatibility to older
versions.5.2 (2017-02-25)FixedtoStrto handle lists, for example a list of class names.
[maurits]Fixed browser to only follow redirects for HTTP statuses
301, 302, 303, and 307; not other 30x statuses such as 304.Fix passing a real file toadd_file.Addcontrolsproperty to Form class to list all form controls.Restore the ability to use parts of the actually displayed select box titles.Allow to set a string value instead of a list onBrowser.displayValue.Fix setting empty values on a select control.Support Python 3.6, PyPy2.7 an PyPy3.3.5.1 (2017-01-31)Alias.browser.urllib_request.HTTPErrorto.browser.HTTPErrorto have
a better API.5.0.0 (2016-09-30)Converted most doctests to Sphinx documentation, and published tohttps://zopetestbrowser.readthedocs.io/.Internal implementation now uses WebTest instead ofmechanize.
Themechanizedependency is completely dropped.This is a backwards-incompatible change.Remove APIs:zope.testbrowser.testing.Browser(this is a big one).Instead of usingzope.testbrowser.testing.Browser()and relying on
it to magically pick up thezope.app.testing.functionalsingleton
application, you now have to define a test layer inheriting fromzope.testbrowser.wsgi.Layer, overrride themake_wsgi_appmethod
to create a WSGI application, and then usezope.testbrowser.wsgi.Browser()in your tests.(Or you can set up a WSGI application yourself in whatever way you like
and pass it explicitly tozope.testbrowser.browser.Browser(wsgi_app=my_app).)Example: if your test file looked like this# my/package/tests.py
from zope.app.testing.functional import defineLayer
from zope.app.testing.functional import FunctionalDocFileSuite
defineLayer('MyFtestLayer', 'ftesting.zcml', allow_teardown=True)

def test_suite():
    suite = FunctionalDocFileSuite('test.txt', ...)
    suite.layer = MyFtestLayer
    return suitenow you’ll have to use# my/package/tests.py
from unittest import TestSuite
import doctest
import zope.app.wsgi.testlayer
import zope.testbrowser.wsgi

class Layer(zope.testbrowser.wsgi.TestBrowserLayer,
            zope.app.wsgi.testlayer.BrowserLayer):
    """Layer to prepare zope.testbrowser using the WSGI app."""

layer = Layer(my.package, 'ftesting.zcml', allowTearDown=True)

def test_suite():
    suite = doctest.DocFileSuite('test.txt', ...)
    suite.layer = layer
    return suiteand then change all your tests from>>> from zope.testbrowser.testing import Browserto>>> from zope.testbrowser.wsgi import BrowserMaybe the blog postGetting rid of zope.app.testingcould help you adapting to this new version, too.Remove modules:zope.testbrowser.connectionRemove internal classes you were not supposed to use anyway:zope.testbrowser.testing.PublisherResponsezope.testbrowser.testing.PublisherConnectionzope.testbrowser.testing.PublisherHTTPHandlerzope.testbrowser.testing.PublisherMechanizeBrowserzope.testbrowser.wsgi.WSGIConnectionzope.testbrowser.wsgi.WSGIHTTPHandlerzope.testbrowser.wsgi.WSGIMechanizeBrowserRemove internal attributes you were not supposed to use anyway (this
list is not necessarily complete):Browser._mech_browserRemove setuptools extras:zope.testbrowser[zope-functional-testing]Changed behavior:The testbrowser no longer follows HTML redirects aka<metahttp-equiv="refresh"... />. This was amechanizefeature which
does not seem to be provided byWebTest.Add support for Python 3.3, 3.4 and 3.5.Drop support for Python 2.5 and 2.6.Drop theWebTest <= 1.3.4pin.  We requireWebTest >= 2.0.8now.Remove dependency on deprecatedzope.app.testing.Bugfix:browser.getLink()could fail if your HTML contained<a>elements with no href attribute
(https://github.com/zopefoundation/zope.testbrowser/pull/3).4.0.3 (2013-09-04)pinning version ‘WebTest <= 1.3.4’, because of some incompatibility and
test failuresMake zope.testbrowser installable via pip
(https://github.com/zopefoundation/zope.testbrowser/issues/6).WhenBrowser.handleErrorsis False, also addx-wsgiorg.throw_errorsto the environment.http://wsgi.org/wsgi/Specifications/throw_errorsPrevent WebTest from always sendingpaste.throw_errors=Truein the
environment by setting it toNonewhenBrowser.handleErrorsisTrue.  This makes it easier to test error pages.Make Browser.submit() handleraiseHttpErrors(https://github.com/zopefoundation/zope.testbrowser/pull/4).More friendly error messages from getControl() et al:when you specify an index that is out of bounds, show the available
choiceswhen you fail to find anything, show all the available items4.0.2 (2011-05-25)Remove test dependency on zope.pagetemplate.4.0.1 (2011-05-04)Add a hint in documentation how to usezope.testbrowser.wsgi.Browserto test a Zope 2/Zope 3/Bluebream WSGI application.4.0.0 (2011-03-14)LP #721252: AmbiguityError now shows all matching controls.Integrate with WebTest.zope.testbrowser.wsgi.Browseris aBrowserimplementation that useswebtest.TestAppto drive a WSGI
application. This this replaces the wsgi_intercept support added in 3.11.Re-write the test application as a pure WSGI application using WebOb. Run the
existing tests using the WebTest based BrowserMove zope.app.testing based Browser intozope.app.testing(leaving
backwards compatibility imports in-place). Released inzope.app.testing3.9.0.3.11.1 (2011-01-24)Fixing brown bag release 3.11.0.3.11.0 (2011-01-24)Addwsgi_interceptsupport (came fromzope.app.wsgi.testlayer).3.10.4 (2011-01-14)Move the over-the-wire.txt doctest out of the TestBrowserLayer as it doesn’t
need or use it.Fix test compatibility with zope.app.testing 3.8.1.3.10.3 (2010-10-15)Fixed backwards compatibility withzope.app.wsgi.testlayer.3.10.2 (2010-10-15)Fixed Python 2.7 compatibility in Browser.handleErrors.3.10.1 (2010-09-21)Fixed a bug that caused theBrowserto keep it’s previouscontentsThe places are:
- Link.click()
- SubmitControl.click()
- ImageControl.click()
- Form.submit()Also adjusted exception messages at the above places to match
pre version 3.4.1 messages.3.10.0 (2010-09-14)LP #98437: usemechanize’s built-insubmit()to submit forms,
allowingmechanizeto set the “Referer:” (sic) header appropriately.Fixed tests to run withzope.app.testing3.8 and above.3.9.0 (2010-05-17)LP #568806: Update dependencymechanize >= 0.2.0, which now includes
theClientFormAPIs.  Remove use ofurllib2APIs (incompatible
withmechanize 0.2.0) in favor ofmechanizeequivalents.
Thanks to John J. Lee for the patch.Use stdlibdoctestmodule, instead ofzope.testing.doctest.Caution:This version is no longer fully compatible with Python 2.4:handleErrors = Falseno longer works.3.8.1 (2010-04-19)Pin dependency onmechanizeto prevent use of the upcoming
0.2.0 release before we have time to adjust to its API changes.Fix LP #98396: testbrowser resolves relative URLs incorrectly.3.8.0 (2010-03-05)Addfollowconvenience method which gets and follows a link.3.7.0 (2009-12-17)Movezope.app.testingdependency into the scope of thePublisherConnectionclass. Zope2 specifies its own version ofPublisherConnectionwhich isn’t dependent onzope.app.testing.Fix LP #419119: returnNonewhen the browser has no contents instead
of raising an exception.3.7.0a1 (2009-08-29)Update dependency fromzope.app.publishertozope.browserpage,zope.browserresourceandzope.ptresource.Remove dependencies onzope.app.principalannotationandzope.securitypolicyby using the simplePermissiveSecurityPolicy.Replace the testing dependency onzope.app.zcmlfileswith explicit
dependencies of a minimal set of packages.Remove unneededzope.app.authenticationfrom ftesting.zcml.Update dependency fromzope.app.securitypolicytozope.securitypolicy.3.6.0a2 (2009-01-31)Update dependency fromzope.app.foldertozope.site.folder.Remove unnecessary test dependency inzope.app.component.3.6.0a1 (2009-01-08)Update author e-mail tozope-devrather thanzope3-dev.No longer strip newlines in XML and HTML code contained in a<textarea>; fix requires ClientForm >= 0.2.10 (LP #268139).Addcookiesattribute to browser for easy manipulation of browser
cookies.  See brief example in main documentation, plus newcookies.txtdocumentation.3.5.1 (2008-10-10)Work around for amechanize/urllib2bug on Python 2.6 missingtimeoutattribute onRequestbase class.Work around for amechanize/urllib2bug in creating request objects
that won’t handle fragment URLs correctly.3.5.0 (2008-03-30)Add azope.testbrowser.testing.Browser.postmethod that allows
tests to supply a body and a content type.  This is handy for
testing Ajax requests with non-form input (e.g. JSON).Remove vendor import ofmechanize.Fix bug that caused HTTP exception tracebacks to differ between version 3.4.0
and 3.4.1.Work around a bug in PythonCookie.SimpleCookiewhen handling unicode
strings.Fix bug introduced in 3.4.1 that created incompatible tracebacks in doctests.
This necessitated adding a patchedmechanizeto the source tree; patches
have been sent to themechanizeproject.Fixhttps://bugs.launchpad.net/bugs/149517by addingzope.interfaceandzope.schemaas real dependenciesFixbrowser.getLinkdocumentation that was not updated since the last
API modification.Move tests for fixed bugs to a separate file.Remove non-functional and undocumented code intended to help test servers
using virtual hosting.3.4.2 (2007-10-31)ResolveZopeSecurityPolicydeprecation warning.3.4.1 (2007-09-01)Update dependencies tomechanize 0.1.7bandClientForm 0.2.7.Add support for Python 2.5.3.4.0 (2007-06-04)Add the ability to suppress raising exceptions on HTTP errors
(raiseHttpErrorsattribute).Make the tests more resilient to HTTP header formatting changes with
the REnormalizer.3.4.0a1 (2007-04-22)Initial release as a separate project, corresponds to zope.testbrowser
from Zope 3.4.0a1