Testing a Simple Web Application with twill and Selenium

The Django "poll" Application

In order to provide you with an example of how to use twill and Selenium to test an application, we're going to take advantage of the Django "poll" application that you build in the Django tutorial, at http://www.djangoproject.com/documentation/tutorial1/.

You don't actually need to go through the Django tutorial to read this section, you can download the source code django-poll-site.zip here. You don't need to know anything at all about Django, either; all you need to do is install Django, install the application, and then follow along below.

Before we get started, honesty compels us to admit that Django has a pretty nice built-in testing framework, django.test. However, that framework is specific to Django—the testing techniques that we demonstrate below apply to any framework in any language, not just Django apps or web sites written in Python.

Installing and running the poll application

  1. Install Django (see http://www.djangoproject.com/documentation/install/).

  2. Download the demonstration app, at http://webtesting.idyll.org/resources/django-poll.zip.

  3. Unpack django-poll.zip (it will unpack into a subdirectory named django-poll) and change into the mysite sub-directory.

  4. Run python manage.py runserver. It will start a web server on http://localhost:8000; to make sure that it is running, visit http://localhost:8000/polls.

You're done!

The First Step: Charting a Path to Test

After you have the Django application ...

Get An Introduction to Testing Web Applications with twill and Selenium now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.