Package: z3c.etestbrowser
Extensions for the Zope 3 testbrowserThis package is intended to provide extended versions of the Zope 3testbrowser. Especially those extensions that introduce dependencies to more
external products, like lxml.ContentsExtensions for the Zope 3 testbrowserExtension: lxml-supportExtended testbrowserRequirementsetree supportStrict XMLLXML unicode supportInvalid XML/HTML responsesHTML/XML normalizationUsing testbrowser on the internetCHANGES4.0 (2023-02-21)3.0.1 (2019-03-05)3.0 (2019-03-04)Backwards incompatible changesFeatures2.0.1 (2015-11-09)2.0.0 (2011-10-13)1.5.0 (2010-08-22)1.4.0 (2010-07-08)1.3.1 (2010-01-18)1.3.0 (2009-07-23)1.2.0 (2008-05-29)Extension: lxml-supportAll HTML pages are parsed and provided as an element-tree.Extended testbrowserThis package provides some extensions tozope.testbrowser.  These are not
included in the core because they have extra dependencies, such aslxml.Requirementslxmletree supportThe extended test browser allows parsing of the result of a request into an
etree using lxml (if the content type is text/html or text/xml).This is useful to perform more detailed analysis of web pages using e.g. XPath
and related XML technologies.Example:>>> from z3c.etestbrowser.testing import ExtendedTestBrowser
>>> browser = ExtendedTestBrowser()
>>> browser.open("http://localhost/")
>>> print(browser.contents)
<!DOCTYPE ...>
...
</html>
>>> browser.etree
<Element html at ...>
>>> browser.etree.xpath('//body')
[<Element body at ...>]Strict XMLIt is possible to force the test browser to use the xml parser:>>> browser.xml_strict
False
>>> browser.xml_strict = True
>>> browser.open("http://localhost/")
>>> browser.etree
<Element {http://www.w3.org/1999/xhtml}html at ...>
>>> browser.etree.xpath(
...     '//html:body', namespaces={'html': 'http://www.w3.org/1999/xhtml'})
[<Element {http://www.w3.org/1999/xhtml}body at ...>]LXML unicode supportA couple of variations of libxml2 might interpret UTF-8 encoded strings
incorrectly. We have a workaround for that. Let’s have a look at a view that
contains a German umlaut:>>> browser.xml_strict = False
>>> browser.open('http://localhost/lxml.html')
>>> browser.etree.xpath("//span")[0].text == u'K\xfcgelblitz.'
TrueInvalid XML/HTML responsesResponses that contain a body with invalid XML/HTML will cause an error when
accessing the etree or normalized_contents attribute, but will load fine for
general TestBrowser use:>>> browser.open("http://localhost/empty.html")
>>> browser.contents
''
>>> browser.etree
Traceback (most recent call last):
ValueError: ...
>>> browser.normalized_contents
Traceback (most recent call last):
ValueError: ...HTML/XML normalizationThe extended test browser allows normalized output of HTML and XML which makes
testing examples with HTML or XML a bit easier when unimportant details like
whitespace are changing:>>> browser.open('http://localhost/funny.html')
>>> print(browser.contents)
<html>
  <head>
    <title>Foo</title>
</head>
    <body>
          <h1>
      Title
    </h1>
        </body>
            </html>
<BLANKLINE>versus>>> print(browser.normalized_contents)
<html>
  <head>
    <title>Foo</title>
  </head>
  <body>
    <h1>
      Title
    </h1>
  </body>
</html>Using testbrowser on the internetThez3c.etestbrowser.browsermodule exposes anExtendedTestBrowserclass that simulates a web browser similar to Mozilla Firefox or IE.>>> from z3c.etestbrowser.browser import ExtendedTestBrowser
>>> browser = ExtendedTestBrowser()It can send arbitrary headers; this is helpful for setting the language value,
so that your tests format values the way you expect in your tests, if you rely
on zope.i18n locale-based formatting or a similar approach.>>> browser.addHeader('Accept-Language', 'en-US')The browser canopenweb pages:>>> browser.open('https://www.w3.org')
>>> print(browser.contents)
<!DOCTYPE html ...
...The World Wide Web Consortium (W3C) is an international community...CHANGES4.0 (2023-02-21)Drop support for Python 2.7, 3.5, 3.6.Add support for Python 3.8, 3.9, 3.10, 3.11.Drop deprecated support forpython setup.py test.Drop deprecatedz3c.etestbrowser.wsgi.3.0.1 (2019-03-05)Fix deprecation declaration in.wsgi.3.0 (2019-03-04)Backwards incompatible changesAdd support forzope.testbrowser >= 5.0which speaks WSGI this requires
tests to be updated to WSGI.Deprecatez3c.etestbrowser.wsgiwhich used to contain the WSGI variant
as it is now the default.Drop thezope.app.testingextra introduced in version 2.0.0 as
it dropped its specialzope.testbrowsersupport.Drop.browser.ExtendedTestBrowser.pretty_printas its requirements are
deprecated or even removed from Python’s StdLib.Adapt the code to newerlxmlversions which no longer raise an exception
if the string to be parsed bylxml.etreeis empty. We now raise aValueErrorin this case.FeaturesAdd support for Python 3.6 up to 3.7.2.0.1 (2015-11-09)Fixover_the_wire.txt2.0.0 (2011-10-13)No longer depending onzope.app.wsgibut onzope.testbrowser>= 4.0
for the WSGI flavor of testbrowser.Added azope.app.testingextra. You should use this extra if you want to
use the browser inz3c.etestbrowser.testing. (The base testbrowser used
there has been moved fromzope.testbrowsertozope.app.testingin
version 4.0.)Renamedz3c.etestbrowser.wsgi.ExtendedTestBrowsertoBrowserfor
equality withzope.testbrowserbut keptExtendedTestBrowserfor
backwards compatibility.1.5.0 (2010-08-22)Addedz3c.etestbrowser.wsgi.ExtendedTestBrowser, a variant that can be
used when the test layer was set up usingusing zope.app.wsgi.testlayer.1.4.0 (2010-07-08)Tookzope.securitypolicyrefactoring andzope.testing.doctestdeprecation into account.Addedz3c.etestbrowser.browser.ExtendedTestBrowser, a variant that
speaks HTTP instead of directly talking to the publisher talks to the
publisher, seeUsing testbrowser on the internet.1.3.1 (2010-01-18)Added doctest tolong_descriptionto show up on pypi.1.3.0 (2009-07-23)Updgraded pacakge to lxml 2.2.Fixed bug withnormalized_contentswhich would break theopenfunction
of test browser if content wasn’t parsable as HTML/XML.1.2.0 (2008-05-29)Addednormalized_contentsattribute that reindents and normalizes the
etree structure of a document and allows easier to read HTML/XML examples in
doctests.