[Zope3-checkins] SVN: Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/ Wrote a couple more tests. This pretty much finishes the easy ones.

Stephan Richter srichter at cosmos.phy.tufts.edu
Wed Jul 27 13:45:08 EDT 2005


Log message for revision 37495:
  Wrote a couple more tests. This pretty much finishes the easy ones.
  
  

Changed:
  U   Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/README.txt
  A   Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/ftests/notitle.html
  A   Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/ftests/zope3logo.gif

-=-
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 17:12:39 UTC (rev 37494)
+++ Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/README.txt	2005-07-27 17:45:07 UTC (rev 37495)
@@ -34,15 +34,69 @@
 
 Making assertions about page contents are easy.
 
-    >>> browser.open('http://localhost/++etc++site/default')
+    >>> 'Simple Page' in browser.contents
+    True
 
-    >>> '<a href="RootErrorReportingUtility">' in browser.contents
+Utilizing the doctest facilities, it is better to do:
+
+    >>> print browser.contents
+    <html>
+    ...
+        <h1>Simple Page</h1>
+    ...
+
+Note: Unfortunately, ellipsis (...) cannot be used at the beginning of the
+output.
+
+
+Checking for HTML
+-----------------
+
+Not all URLs return HTML. Of course our simple page does:
+
+    >>> browser.open('http://localhost/@@/testbrowser/simple.html')
+    >>> browser.isHtml
     True
 
+But if we load an image (or other binary file), we do not get HTML:
 
+    >>> browser.open('http://localhost/@@/testbrowser/zope3logo.gif')
+    >>> browser.isHtml
+    False
+
+
+HTML Page Title
+----------------
+
+Another useful helper property is the title:
+
+    >>> browser.open('http://localhost/@@/testbrowser/simple.html')
+    >>> browser.title
+    'Simple Page'
+
+If a page does not provide a title, it is simply ``None``:
+
+    >>> browser.open('http://localhost/@@/testbrowser/notitle.html')
+    >>> browser.title
+
+However, if the output is not HTML, then an error will occur trying to access
+the title:
+
+    >>> browser.open('http://localhost/@@/testbrowser/zope3logo.gif')
+    >>> browser.title
+    Traceback (most recent call last):
+    ...
+    BrowserStateError: not viewing HTML
+
+
 Headers
 -------
 
+As you can see, the `contents` of the browser does not return any HTTP
+headers. The headers are accessible via a separate attribute:
+
+    >>> browser.open('http://localhost/@@/testbrowser/simple.html')
+
 The page's headers are also available as an httplib.HTTPMessage instance:
 
     >>> browser.headers
@@ -54,7 +108,9 @@
     Status: 200 Ok
     Content-Length: ...
     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:
 
@@ -65,6 +121,8 @@
 Navigation
 ----------
 
+    >>> browser.open('http://localhost/++etc++site/default')
+
 If you want to simulate clicking on a link, there is a `click` method.
 
     >>> browser.click('RootErrorReportingUtility')

Added: Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/ftests/notitle.html
===================================================================
--- Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/ftests/notitle.html	2005-07-27 17:12:39 UTC (rev 37494)
+++ Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/ftests/notitle.html	2005-07-27 17:45:07 UTC (rev 37495)
@@ -0,0 +1,5 @@
+<html>
+  <body>
+    <h1>No Title</h1>
+  </body>
+</html>
\ No newline at end of file

Added: Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/ftests/zope3logo.gif
===================================================================
(Binary files differ)


Property changes on: Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/ftests/zope3logo.gif
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream



More information about the Zope3-Checkins mailing list