[TIP] Capture HTTP traffic

Alex alex.lavoro.propio at gmail.com
Wed Nov 3 03:10:21 PDT 2010


I am developing an automated test in Python/Windows and I have to
ensure certain HTTP requests are made and verify the GET parameters
and responses. I need a tool to help me easily to capture and filter
the HTTP requests.

A typical test case is like:

    def setUp()
        self.capture = HttpCapture() # hypothetic
    def testFoo(self):
        self.capture.start("http://update.foobar.com")
        subprocess.Popen(...)
        self.capture.end()
        # suppose self.capture.result() returns a list of strings,
containing the URLs
        # have been visited betwen begin() and end()
        self.failUnless("http://update.foobar.com/" in
self.capture.result() )

 It seems to me that it's not trivial to integrate 'pycap' into this
picture. I wouldn't mind that the hypothetic HttpCatpure() launchs an
external application. In fact, I did try to automate Wireshark by
myself but it didn't seem to fit well into this test case design
neither.



More information about the testing-in-python mailing list