Testing a website with HTTPS login and cookies

John J. Lee jjl at pobox.com
Thu Sep 7 18:40:02 EDT 2006


Hari Sekhon <hpsekhon at googlemail.com> writes:

> I want to create a test that will do a proper login test to a web site
> but I need some pointers.
> 
> I need to login to the website by accessing an https url and posting
> to that, which should return a very small 302 reply with the address
> of the internal page. I need to take that page href and then access
> it, if I can do all that then the test passes. Of course because I
> have to access two urls I also need cookies for session handling. I've
> already tried bash which would have worked but for the cookie handling
> and webinject which is written in Perl, but this doesn't do exactly
> what I want in terms of output so I'd rather write something
> myself. (I'm also curious as to the best way to do this)
> 
> If anybody knows how to do this could they please give me a quick
> pointer and tell me what libraries I need to go read up on?

You could just use httplib, or urllib2 (using
urllib2.HTTPCookieProcessor) if you need to handle cookies.  However,
personally I prefer using a higher-level tool that knows a bit more
about web-browser behaviour, e.g.:

http://www.idyll.org/~t/www-tools/twill.html
http://cheeseshop.python.org/pypi?%3Aaction=display&name=ZopeTestbrowser


both of which are based on:

http://wwwsearch.sourceforge.net/mechanize/


(BTW, I hear there's work going on on an implementation of
zope.testbrowser that delegates to Selenium instead of to mechanize --
cool.)


John



More information about the Python-list mailing list