Quick Start With FitNesse and Selenium

Several months ago I used Selenium for web application testing, writing all my tests in Java. That was a nice experience except that writing tests in Java is somewhat verbose. So, after reading nice things about FitNesse I decided to give it a try. My idea was to stay with Selenium’s engine for running tests but to keep all test scripts nicely organized as wiki pages on a FitNesse server. I’ve found an excellent post by Gojko Adzic about connecting FitNesse and Selenium but it was a bit advanced for me. The other documentation I’ve found was also weak in that sense. I needed more like a beginner’s guide but no luck. So, here’s my version of it…


To connect FitNesse and Selenium you’ll need the following:

  1. Download the latest FitNesse jar.

  2. Download WebTest Fixtures extension for FIT/FitNesse. It is also distributed as a jar file.

  3. Download FitLibrary.

  4. Download Selenium Remote Control.

That’s maybe more components than expected but you’d need all of these as each one has a separate role:

  • Selenium Remote Control (RC) is a test tool that allows you to write automated web application UI tests.

  • FitNesse is a wiki with an extensible framework that allows software teams to define acceptance tests, run tests and see the results.

  • WebTest Fixtures library is a bridge between the above two that allows you to write tests in a friendly, “almost English” language.

  • FitLibrary is a dependency of WebTest but it’s a bag of goodies for FitNesse on its own.

I’ll be installing FitNesse on my local machine but I’ll put Selenium RC on a separate virtual machine (I’ll call it browsers-vm here) with referent browser installations that I use for testing.

All these tools are written in Java so you’ll need Java installed as well.

Setting up FitNesse with WebTest Fixtures, etc.

First, create a directory that will be the home of your FitNesse installation and put the fitnesse.jar to it. Then, start FitNesse from the command line:

java -jar fitnesse.jar

When start FitNesse for the first time, directory named FitNesseRoot will be created containing initial wiki pages and other application resources. By default, FitNesse will try to bind to port 80; if the port is already in use FitNesse will exit and you’ll have to start it again specifying some other (free) port using “-p . When started, you should see something like this in console:

FitNesse (v20100303) Started...
 port:              80
 root page:         fitnesse.wiki.FileSystemPage at ./FitNesseRoot
 logger:            none
 authenticator:     fitnesse.authentication.PromiscuousAuthenticator
 html page factory: fitnesse.html.HtmlPageFactory
 page version expiration set to 14 days.

At this point you can access FitNesse directing your browser to http://localhost (adding port to the URL if you’re not using default 80). That’s sufficient for now. As we still need to install other libraries shut FitNesse down (Ctrl+C should be fine).

Next, put files webtest.jar (for convenience, I renamed it from the originally downloaded webtest-2.01-20080109.jar) and selenium-java-client-driver.jar (get it from downloaded Selenium zip archive) to the FitNesse’s home directory. Then, extract downloaded FitLibrary zip to a temporary location and copy content of its fitnesee directory into your FitNesse’s home directory. (Notice that you should copy “into”, without overwriting any existing files.) On Linux that would be something like:

cp -R /path/to/tmp/FitLibrary20100806/fitnesse/* /path/to/fitness/

If all fine, FitNess home should contain 4 jar files (fitlibrary.jar, fitnesse.jar, selenium-java-client-driver.jar, webtest.jar) and directories FitNesseRoot and lib.

That’s it. Now you can start FitNesse server again:

java -jar fitnesse.jar

Running Selenium RC

From downloaded zip archive extract selenium-server.jar. This is the only file required to start Selenium Remote Control. Save it to any directory you like. (I put the jar to a separate system with browser installations but you can run Selenium RC on the same system where FitNesse is installed.)

If you’re on Windows, you can double click on selenium-server.jar and Selenium RC should start in the background. By default, Selenium will start on port 4444.

To start Selenium from a command line, go to the directory where you put its jar file and type:

java -jar selenium-server.jar

or to start it on a different port (e.g. port 1234):

java -jar selenium-server.jar -port 1234

Making the first test page

Now, back to FitNesse… Edit the home page (or any other page where you’d like to have your page linked) and add a wiki word to it, for example MyFirstTestPage. Next, open the MyFirstTestPage page for editing and paste the following block of text to it:

Hi Fitnesse

!define TEST_RUNNER {fitlibrary.suite.FitLibraryServer}
!path fitlibrary.jar
!path webtest.jar
!path selenium-java-client-driver.jar

|Start Browser |firefox|With Selenium Console On|browsers-vm|At Port|4444|And Scripts At|http://www.google.com|
|user Opens URL|http://www.google.com|
# some test methods here
|shutdown browser|

Replace the “browsers-vm” with name (or IP address) of the system running the Selenium server. Save the page, click the Test link (will appear as the first item in the menu) and watch what’s going on the system where you’re running Selenium. Hopefully, you should see Firefox windows appearing, opening Google’s home page and then Firefox closing. That was it. If all was fine, at the top of the wiki page you’ll see:

Assertions: 0 right, 0 wrong, 0 ignored, 0 exceptions

Now it would be a good time to change Google’s URL with your application’s and start adding some real testing code.

Few more things:

  • Test menu item will not appear if you don’t have “Test” in the name of your wiki page. It’s convenient to follow notation having Test in the page name but you can also tell FitNesse to treat the page as a test. Click the Properties item in the menu and change page type to “Test”. After you save the properties, the Test link will appear as the first menu item.

  • Notice the define and path directives in above sample. They are needed on every page that uses tests with WebTest Fixtures. Fortunately, you can move these to the global configuration; just edit the “root” page linked in the footer of your wiki page.

Further research…

I covered installation process only without going into all details and possible options. You should check out documentation of FitNesse and WebTest for the reference.You’ll probably want to get familiar with organizing your tests in Suite, etc.

I recommend you to check out FitLibrary documentation too. If you followed above installation steps you already have it installed in your FitNesse instance; just add a link to it adding “FitLibrary” to your FitNesse home page. The FitLibrary comes with many useful extensions such as defined actions, dynamic variables, etc.

Edit: Although I generally liked FitNesse, after more playing with it I was a bit disappointed because support for Selenium RC is not really complete. For example, I wanted to create a test for one of my legacy applications that uses HTML frames. However, I could not find any support for selecting a browser window or frame although it exists in Selenium. I checked both DoFixture and PlainSeleniumTest but nada. Fortunately, the source code for WebTest is available so I added missing methods and was able to continue with my experiment. (I wish I didn’t have to patch WebTest’s libraries. The methods I added are trivial (one line only) as invocation is only passed to the Selenium instance. I suspect that more Selenium’s methods may be missing and that some people (non-developers) will be stuck and simply give up.)