Tuesday, December 8, 2009

Adding External Pages to FitNesse

Caveat: This will be of interest only in the tiny world of FitNesse maintainers!

I've recently completed a version 1 implementation that allows folders of HTML files to appear as read-only pages in the FitNesse wiki. These pages can be executed as tests, navigated and searched as if they were actual wiki pages. This is a brief technical description of this implementation.

FitNesse already contains a class hierarchy of wiki page types, rooted at WikiPage. FileSystemPage is the concrete class that represents a normal wiki page. I added two new classes, ExternalSuitePage and ExternalTestPage, to represent a folder of HTML files and an individual HTML file.

FileSystemPage had an existing method, createChildPage, that created FileSystemPage objects for each of its sub-folders. I modified this method to use the following rules:
  • a folder with a context.txt file is a FileSystemPage
  • a folder with any *.html files is an ExternalSuitePage
Each WikiPage implementation has to provide methods for page content, attributes and children. The content for ExternalSuitePage is always "!contents" and its attributes are "Suite". It has ExternalTestPage children for all its HTML files and ExternalSuitePage children for all its subfolders of HTML files. The content for ExternalTestPage is its file contents wrapped in "!-" and "-!" and its attributes are "Test".

Within the scope of my changes, I made a couple of refactorings. I created a PageRepository class to encapsulate the knowledge of how pages are stored in the file system. I also created a FileSystem interface with production (disk-based) and test (memory-based) implementations so I could write tests that created various file system states without hitting the real file system.

This first version of the feature works well: I've used it on my fitSharp test suite of over a hundred HTML files. But there are a few caveats:
  • If you use the ?edit or ?properties URL syntax, you can get to the edit and properties pages, but they will fail if you try to save.
  • The contents of the HTML files are placed as is inside a FitNesse page, and may break the page display if there are unbalanced tags or other HTML problems that may not be apparent when the HTML is displayed on its own.
  • Hyperlinks, images, Javascript files and other external references in the HTML may not behave as expected when placed inside a FitNesse page.
  • Wiki page names are generated from the HTML file names, but there is no check to avoid potential name collisions. For example, TestA.html and testa.html will both generate TestA as a wiki page name.
Feel free to work on any of these issues - I'll probably come back to it in a while but I've got a list of other things I want to work on!

No comments:

Post a Comment