Introduction to Functional Web Testing With Twill & Selenium

Part 1 :: Extra Time :: Directory Structure

Synopsis

This might be more apparent to more advanced users, but wasn't apparent to me when I started working as a tester. Through a lot of inverted designs, poor design decisions and trial and error, I think the following directory structure can work well for your test suites.

A Directory Structure That Works For Me

I used to fear os.path in a very deep way. In fact, it creeped me out so much that I just generally avoided reading code that used it. Eventually, you have to come to grips with how you've set up your tests so that there's a great balance between organization and logical use. The following setup seems to work well for my experiments:

              [terryp@tpmacbook] sample_layout :: tree tw/
              tw/
              |-- lib
              |   |-- __init__.py
              |   |-- page
              |   |   |-- __init__.py
              |   |   `-- page.py
              |   |-- sample_lib.py
              |   `-- utils
              |       |-- __init__.py
              |       |-- config.py
              |       `-- url.py
              `-- test_something.py

              3 directories, 8 files
            

The easiest way to explain it is to step through the output from the tree command. All of my Twill tests are self contained in a 'tw' directory. You can see there's a test file called 'test_something.py' in the 'tw' directory.

Inside the 'tw' directory is a single 'lib' directory. This 'lib' directory is used for suite-level modules like 'sample_lib.py.' What are suite-level modules? Well, anything that you want your entire suite to have common access to. These could be fixtues, order factories, fuzzers.

The 'lib' directory contains two subdirectories, 'page' and 'utils.' The 'page' directory is what I used to call a page class, which we'll talk about a little later. Think of a page class as the most generic representation of a web page; it's an easy way to centralize common methods you reuse all the time.

The 'utils' directory is what I use for little hacks, and I call it 'utils' because calling it 'hacks' seems a bit amateur. This is generally where I keep configuration information or url parsers or other small, helpful utility modules.

Fluid 960 Grid System, created by Stephen Bau, based on the 960 Grid System by Nathan Smith. Released under the GPL/ MIT Licenses.