FitNesse Training: 2. How to get started with FitNesse

Daniël Verburgh
Testautomation Computest
9 min readNov 17, 2020
Photo by Austin Distel on Unsplash

Notes: This training is part of a series of 7, the complete series can be found here.
We have used FitNesse with HSAC fixtures for this training-series.

In the previous article, you have learned the advantages of using FitNesse. Now let’s have a look at how to set up your first FitNesse project.

First, let’s talk about the FitNesse markup syntax. All your tests and setup pages are going to be inside tables. So you have to use vertical strokes for almost everything. More Markup Language information can be found here.

Secondly, everything will be written on pages. Our setup, tests, variables, navigation, reusable tests (scenarios). So we won’t work in files. You really have to see this as a wiki that can run tests.

Now we have these two important things clear. Let’s set up your first FitNesse-project!

Getting started with FitNesse step by step

In this article, we will show you in small steps how to set up your first FitNesse project. Before you start, make sure you have Chrome and Java installed.

Step 1- Download the appropriate Zip file
For this tutorial, we will use the hsac-fitnesse-fixtures project standalone.zip. Download the latest release on GitHub.

Step 2 — Opening the right zip file
If you are working on a Mac open your Terminal, if you work on Windows open your Command Prompt.

Step 3 Navigate into your Downloads folder
Type cd ./Downloads on your Terminal or Command Prompt to navigate into your Downloads folder.

Step 4 — Extract the standalone zip

  • On your Mac: open with Archive Utility (make sure you don’t have space in your folder name) or mkdir fitnesse && unzip hsac-fitnesse-fixtures-<ADD-YOUR-VERSION-HERE>-standalone.zip -d ~/Downloads/fitnesse && cd fitnesse.
  • On Windows: Right-click on the folder and select Extract All (make sure you don’t have space in your folder name) or mkdir fitnesse && jar xf hsac-fitnesse-fixtures-<ADD-YOUR-VERSION-HERE>-standalone.zip && cd fitnesse
  • If you receive the following error: ’jar’ is not recognized as an internal or external command, then you don’t have Java installed. You can download java here.

Step 5Open the folder
Open the hsac-fitnesse-fixtures-<ADD-YOUR-VERSION-HERE>-standalone folder, that was created when you extracted the zip file, in your terminal.

For example, if it’s in your Downloads folder. You should just cd into it.

Step 6 — Starting FitNesse
Now fill in the following command into your terminal and press enter: java -jar fitnesse-standalone.jar -p 9090 -e 0 -lh , FitNesse will start. This will take about 20 seconds.

Are you curious about why we use “-e 0 -lh”? You will find more info and arguments in this GitHub-article.

Step 7 — Navigate to the right page
Navigate to http://localhost:9090/ in your browser

Step 8 — Check if you are on the right page
You should see this page in your browser. This is the homepage of your FitNesse project.

Write your first test case
Now that you have a FitNesse-project running, we want to make sure you have a running test case, just to confirm that everything is working properly and for you to have an example of the basic architecture of a FitNesse project. In our next article; ‘How to properly write your first own test case’ we will explain into detail how to set up this test case.

Step 9 — Create a suite
Now before we start writing our first test case, we have to add a suite. You can think of a suite as a folder in which all your test cases can be stored. If you would want to run all your test cases at once you could simply just run the suite. There should always be one main suite where your tests are stored. You can’t create a test outside a suite page. Now, click on ‘Add’. A drop-down menu will appear. Now click on ‘Suite Page’.

Step 10 — Name your suite
First, we have to give a name to our suite. Insert the following Page name: MyTestSuite

Step 11 — Specify the page field
Every page has a page field where you specify your setup, test steps, variables or documentation. In the page field, insert the following:

This is my first test suite.!contents -R2 -g -p -f -h!*> Basic setup for tests with Slim
Workaround for https://github.com/unclebob/fitnesse/issues/989
!define slim.port {0}
!define TEST_SYSTEM {slim}
!define ALL_UNCLE_SUITE_SETUPS {true}
The classpath location:
!path fixtures
!path fixtures/*.jar
*!

Step 12 — Defining the test system
Above we first define the Port for FitNesse to listen on. Next, we define the test system. We use the Slim server, but there is also the Fit server system. Just see this as starting the system under test with some extra code.

Here you can find more information about the FitNesse architecture

The variable ALL_UNCLE_SUITE_SETUPS changes the default behaviour of the SuiteSetup and the SuiteTearDown. With the SuiteSetup and SuiteTearDown you can perform operations like delete a test database or empty a database at the beginning of each test. You do this by writing special fixtures that perform these functions. These fixtures can be invoked in the SuiteSetup and SuiteTearDown pages. By default, only the ‘nearest’ uncle SuiteSetUp and SuiteTearDown pages are executed. The variable ALL_UNCLE_SUITE_SETUPS changes this default behaviour and makes sure that all SuiteSetUp and SuiteTearDown up in the hierarchy are executed before each test. More information can be found here

Step 13 — Using a Class Path
We already mentioned fixtures before, a fixture is a class that FitNesse and Slim use to process a particular test table when the Test button is clicked. For each row of data in a test table, Slim sets its inputs using setter methods, and then calls the specified output methods. FitNesse uses the return values to determine whether to turn output table cells green or red. You need to use a Class Path to specify to Slim where your fixture code resides and that’s what we do in the last 3 rows of the page field.

By now you should have something like this:

Click ‘Save’

Step 14 — Add a link to your new suite
Add a link to your newly created suite on the FrontPage by clicking on ‘Edit’ in the header and paste the following a row of your choice: [[My Test Suite][.FrontPage.MyTestSuite]] and click ‘Save’

Step 15 — Click on the link
Now click on the link you just created or go to this URL: http://localhost:9090/FrontPage.MyTestSuite

Step 16 — Creating SuiteSetUp
Now click on ‘Add’ and next on ‘Static Page’ from the dropdown menu. We are now going to create the SuiteSetUp we talked about above.

Step 17 — Creating a page name
Give the following Page name: SuiteSetUp

Step 18 — Insert static page
In the Help text field, insert Static page. Defines where to look for fixture code.

Step 19 — Fill in the following text in the page field:

This set up page is executed once, before any tests in this suite.An [[import table][.FitNesse.UserGuide.WritingAcceptanceTests.SliM.ImportTable]] defines which Java packages may contain fixture classes.| Import                        |
| nl.hsac.fitnesse.fixture.slim |

Step 20 — Check the page field
Check if the page field looks something like this:

Step 21 — Click ‘Save’

Step 22 — Creating a new suite in your existing suite
Now we will create a new suite in our existing suite. You can create as many suites as you want. This enables us to run a suite we can separately without having to run the other suites. Click on ‘Add’ and next on ‘Suite Page’.

Step 23Enter page name
Enter the following Page name: SmokeTests

Step 24Navigate
Navigate into your new SmokeTests Suite

Step 25 — Create a static page
Create another static page by clicking ‘Add’ > ‘Static Page’.

Step 26 — Setting up SuiteTearDown
We are now going to create the SuiteTearDown for the SmokeTests. SuiteName for this page should be: SuiteTearDown and add this text in the page field: Static page. Defines where to look for fixture code, and ensures browser is started.

Step 27 — Filling in the text in the page field
Fill in the following text in the page field:

This set up page is executed once, after all tests in this suite.| script| selenium driver setup |
| show | run summary |
| stop driver |

Step 28 — Check the page field
Check if the page field it looks something like this and click ‘Save’

Step 29 — Creating the SuiteSetUp page
Time to create the SuiteSetUp page for our SmokeTests Suite now. As with the teardown, create a new ‘Static Page’ from the Add dropdown menu. Name the page SuiteSetUp and write Static page. Defines where to look for fixture code and ensures browser is started in the Help text field.

Then copy the following the page field:

This set up page is executed once, before any tests in this suite.
In it we configure which Java packages contain the logic for our fixtures, which browser we want to use for Selenium tests and we start this browser.
This means we do not have to do this in every test, which means easier maintenance and better performance.
Stopping the browser is done in SuiteTearDown, which is done after all tests in this suite are completed.| Import |
| nl.hsac.fitnesse.fixture.slim.web |
| script | selenium driver setup |
| start driver for | chrome |
| show | driver description |

Step 30 — Check the Suite SetUp page
Check if the Suite SetUp page looks like this and then click Save.

Create a test case
Nice job so far! Now let’s create a test case and run it to see if everything is working as expected. We are going to write a simple test where we search a particular webpage in google and then verify if we are on that webpage.

Step 31 — Check your MyTestSuite
Now navigate to MyTestSuite Suite. Just to check that your MyTestSuite is the same as the one in the screenshot below.

Step 32 — Open your Smoke Test Suite
Click on ‘Smoke Tests’ to open your Smoke Test Suite.

Step 33 — Creating our first test inside our Smoke Tests Suite
We are now going to create our first test inside our Smoke Tests Suite. Click on ‘Add’ > ‘Test Page’ and name your test OpenWebAppTest

Step 34 — Copy this text in the page field
Remember how FitNesse aims to be easy to use for everyone also for non-programmers? When you look at these test scripts, it’s pretty obvious what it’s meant to do.

Copy this in the page field.

| script           | browser test                       |
| open | https://google.nl |
| wait for visible | id=hplogo |
| type | the internet herokuapp |
| press | enter |
| click | The Internet |
| ensure | is Visible|Welcome to the-internet |

Step 35 — Check the test scripts
Check if the test scripts look something like this:

Step 36 — Save the test scripts
Click ‘Save’

37 — Start your first test
Click on ‘Open Web App Test’ and now on ‘Test’ in the header, right next to the FitNesse logo. Your test will start. Wait for it to finish.

38 — Check if your first test was successful
This is how it will look when your test is successfully finished:

Your first working FitNesse project
Great job! You have now successfully set up your first working FitNesse project. In the next article we will cover setting up suites into more detail but for now, our first goal ‘how to get started with FitNesse’ has been reached.

Continue to the next story.

--

--