Web functional testing in a rapid-development environment

QA for Divmod's Quotient

Functional testing used in addition to unit-testing

Tests are specified in a list of Nevow stan-tag like objects called NavTags.

so what's under the hood?

First thing's first

As a design decision, we added id attributes to our dom nodes.

<link id=”signin” ...>

Using Divmod's Nevow, this is fairly trivial to autogenerate.

Step 2: The Hard Part

Write a halfway decent http client

or get Moshe Zadka to write one for you.

After you make a request and receive the response, two important things happen:

The client saves the retrieved page and creates a link to it in a “urltrail” file.

(this is so you can fire up Mozilla and see why your test barfed)

The client returns the dom and twisted.web.microdom parses the tree into a Page class.

The Page class provides getForm and getLink methods

You can then make assertions about strings that should be contained in the dom, or you can navigate to any link or post to any form on that Page

signinData = {'username': 'tester3',

'password': 'sekrit'}

self.runSequence(url('/'),

form('signin', **signinData),

link('Mail'),

assertString('Inbox'))

The advantage to using this method is that you can specify all of the steps in the sequence using Python.

Through use of the Twisted Component system, you can use list comprehensions, tuples, and functions in your sequence, and the framework will simply do

The Right Thing.

for pri, names in priAndSecNav.iteritems():

s = [[link('SecNav.%s' % name), notraceback]

for name in names]

self.runSeq(signin, metapup, notraceback, pri, s)

signin = [logout, url('/'), form('signin',

**signinData)]

metapup = url('/me/1/')

notraceback = assertNotString('SorryRenderer')

or something as simple as...

a = 'eddie.izzard@example.net'

self.runSeq(signin,

link('leftnav.Mail'),

link('SecNav.Mail Settings'),

link('Table.Whitelist'),

form('addAddress', add=a),

notraceback,

assertString(a))

You wind up with a simply expressed, highly-readable, pure-Python way of performing web unit testing.

...and you never have to touch XML

2004-03-25T00:10:16