[twill] Passing local html files to twill?

Christopher Rasch crasch at openknowledge.org
Thu Feb 16 18:02:28 PST 2006


Hi,

I want to write a twill test function that will

a.  browser to a given url
b.  test to see if the page returned is the expected page or not

In order to test that the test itself is working correctly, I want to  
pass sample "known good" and "known bad" html pages to the test  
function, and see if it passes or fails.

I have a directory containing of a bunch of sample html pages.  I  
tried to "browse" to a file in the directory, but it didn't work.   
How can I pass an html file to twill so that I can use twill's  
assertion code?  Is there a better way to do what I want to do?   
Thanks for any help you may wish to provide.

Chris



Here's the code I tried:

def test_mtacohomepage():
   script = "title 'Marketocracy :: Finding the Best Investors in the '"
   twill.execute_string(script, initial_url='file:///Users/crasch/ 
Projects/trunk/Scripts/Python/PortfolioTests/test_html/ 
unexpected_error.html')

crasch:~/Projects/trunk/Scripts/Python/PortfolioTests/nosetests crasch 
$ nosetests
E
======================================================================
ERROR: test_login.test_mtacohomepage
----------------------------------------------------------------------
Traceback (most recent call last):
   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ 
python2.4/site-packages/nose-0.8.6-py2.4.egg/nose/core.py", line 112,  
in runTest
     self.testFunc()
   File "/Users/crasch/Projects/trunk/Scripts/Python/PortfolioTests/ 
nosetests/test_login.py", line 21, in test_mtacohomepage
     twill.execute_string(script, initial_url='file:///Users/crasch/ 
Projects/trunk/Scripts/Python/PortfolioTests/test_html/ 
unexpected_error.html')
   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ 
python2.4/site-packages/twill-0.8.2-py2.4.egg/twill/parse.py", line  
140, in execute_string
     _execute_script(fp, **kw)
   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ 
python2.4/site-packages/twill-0.8.2-py2.4.egg/twill/parse.py", line  
173, in _execute_script
     commands.go(init_url)
   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ 
python2.4/site-packages/twill-0.8.2-py2.4.egg/twill/commands.py",  
line 95, in go
     browser.go(url)
   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ 
python2.4/site-packages/twill-0.8.2-py2.4.egg/twill/browser.py", line  
102, in go
     self._last_result = journey(self._browser.open, u)
   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ 
python2.4/site-packages/twill-0.8.2-py2.4.egg/twill/utils.py", line  
68, in journey
     new_result = ResultWrapper(result.code, # HTTP response code
   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ 
python2.4/site-packages/twill-0.8.2-py2.4.egg/twill/wwwsearch/ 
ClientCookie/_Util.py", line 425, in __getattr__
     return getattr(wrapped, name)
AttributeError: addinfourl instance has no attribute 'code'


----------------------------------------------------------------------
Ran 1 test in 1.006s

FAILED (errors=1)


isError(body)





More information about the twill mailing list