iTranslated by AI
Writing Acceptance Test Specifications with FitNesse
Overview
FitNesse is an acceptance testing framework where you write specifications in a wiki and can execute them directly as automated tests.
It supports data-driven tests by specifying input and expected values in tables on the wiki, as shown below:

It also enables keyword-driven-like tests by describing steps (keywords) in tables:

FitNesse started as an HTML/Wiki frontend for FIT (Framework for Integrated Testing). It has been continuously released at least since around 2006, making it a long-standing tool.
This article introduces a simple way to use FitNesse. If you want to read detailed documentation, please refer to the official User Guide.
As mentioned above, although FitNesse is still maintained, it is a tool with a long history. Since there are now more options than in the past, if you are planning keyword-driven testing from scratch, it is recommended to also consider alternatives such as Robot Framework.
The following is a comparison of Robot Framework and FitNesse on Google Trends:

Simple Example
Start Docker containers for FitNesse and Selenium, and verify a simple browser test sample.
- Clone the following repository:
- Build and start the containers:
docker compose build
docker compose up
-
Access
http://127.0.0.1:8080 -
Select the browser test sample:

-
Choose "Open Browser":

-
Run the test by clicking "Test" at the top of the page:

Selenium running on the Selenium container will operate the browser.
- The test results are displayed. Items that executed successfully are shown in green:


Explanation of the Simple Example
This simple example was created with reference to the following page:
FitNesse Training: 2. How to get started with FitNesse
The difference is that we use a remote Selenium in a separate container instead of a local one, but the basic approach follows the method described on that page.
Notes When Following How to get started with FitNesse
Though "How to get started with FitNesse" is an excellent tutorial, there are some points to note when actually running it.
Step 6 — Starting FitNesse
There are almost no hints for troubleshooting, so it is safer to add the -v option. This will display detailed logs.
Step 11 — Specify the page field
While the path to fixtures is specified in the path field, it is safer to use an absolute path.
Step 34 — Copy this text in the page field
This example performs a Google search, but currently, Google searches via Selenium may be blocked.
It is recommended to change to a suitable page, as in this example.
Step 38 — Check if your first test was successful
It will likely result in an error.
Check the error message on the screen or the log messages in the Docker container and respond accordingly.
If a chromedriver error occurs, download a new chromedriver and replace the existing webdriver driver.
On macOS, the downloaded chromedriver cannot be executed as-is, so you need to unblock it in Security & Privacy.
How the Simple Example Works

The wiki table is converted into a list of instructions and sent to the Slim server.
The Slim server generates BrowserTest instances according to these instructions.
BrowserTest acts as a Selenium WebDriver client, operating and verifying the browser via a remote or local driver depending on the configuration.
Creating a Test Suite
To write acceptance tests, you first need to create a test suite.
Here, you can group similar tests together, and specify SetUp and TearDown processes for each test.
On the top page or similar, select Add → Suite Page:

Enter a Page name. The page will be accessible using this name:

For example, if you enter "BrowserTests", it will be accessible at http://127.0.0.1:8080/FrontPage.BrowserTests.
In the content of the test suite, you can describe the test suite's content and configure settings shared across the suite.
The content of the BrowserTests test suite in the Docker setup is as follows:
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 /opt/fitnesse/fixtures
!path /opt/fitnesse/fixtures/*.jar
*!
The items under "Basic setup for tests with Slim" are configuration settings for running the tests.
- slim.port: Specifies the port on which Slim runs.
- TEST_SYSTEM {slim}: Switches the test execution system to Slim.
- ALL_UNCLE_SUITE_SETUPS: Required to define SuiteSetUp and SuiteTearDown (described later).
- path: Adds the classpath to be used for tests.
Adding SuiteSetUp to a Test Suite
In some cases, you need to execute common setup processing before each test run.
In such cases, add SuiteSetUp from the test suite.
First, navigate to the test suite page.
(In this example: http://127.0.0.1:8080/FrontPage.BrowserTests)
Select Add → Static Page from the top menu:

The input screen appears:

Page name: SuiteSetUp
Content:
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|
|connect to driver for|chrome|at|http://selenium:4444/wd/hub|
| show | driver description |
| Import |
| nl.hsac.fitnesse.fixture.slim.web |
This is used to import the library used in the page.
Here, we import nl.hsac.fitnesse.fixture.slim.web.
|script|Selenium driver setup|
This uses a ScriptTable to perform operations.
First, the first line Selenium driver setup instantiates the SeleniumDriverSetup class.
|connect to driver for|chrome|at|http://selenium:4444/wd/hub|
This calls connectToDriverForAt with arguments chrome and http://selenium:4444/wd/hub:
obj.connectToDriverForAt("chrome", "http://selenium:4444/wd/hub");
According to the Graceful Naming rules, the text in the odd-numbered columns of the table is concatenated into camelCase to form the method name, and the even-numbered columns are passed as parameters.
| show | driver description |
This is an instruction to display the result of the driverDescription method.
When the test is executed, the driver details will be displayed as follows:

Adding SuiteTearDown to a Test Suite
In some cases, you need to execute common cleanup processing after each test run.
In such cases, add SuiteTearDown from the test suite.
First, navigate to the test suite page.
(In this example: http://127.0.0.1:8080/FrontPage.BrowserTests)
Select Add → Static Page from the top menu:

The input screen appears:

Page name: SuiteTearDown
Content:
This set up page is executed once, after all tests in this suite.
| script| selenium driver setup |
| show | run summary |
| stop driver |
This instantiates the SeleniumDriverSetup class and executes runSummary and stopDriver.
Adding Test Cases to a Test Suite
To actually execute tests, add a new page.
First, navigate to the test suite page.
(In this example: http://127.0.0.1:8080/FrontPage.BrowserTests)
Select Add → Test Page from the top menu:

Page name: OpenBrowser
Content:
|script|browser test|
|open|https://the-internet.herokuapp.com|
|wait for visible|link=Add/Remove Elements|
|show|take screenshot|home-page|
|show|save page source |
|click|link=Add/Remove Elements|
|wait for tag|h3|with text|Add/Remove Elements|
|show|take screenshot|home-page|
|show|save page source |
Before the tests on this page are executed, the script from the SuiteSetUp page runs, which applies common Selenium configurations.
The actions performed in this test page are as follows:
- Instantiates the BrowserTest class
- Uses open to open
https://the-internet.herokuapp.com. - Passes
link=Add/Remove Elementsto waitForVisible. This waits until the text "Add/Remove Elements" is displayed. -
|show|take screenshot|home-page|Takes a screenshot and displays it in the test results. -
|show|save page source |Saves the page source code and displays it in the test results. -
click clicks the element with
link=Add/Remove Elements. - Uses waitForTagWithText to wait until an h3 tag with "Add/Remove Elements" appears.
- Takes a screenshot and saves the page source.
After the tests on this page finish, the script from the SuiteTearDown page runs to perform Selenium cleanup.
Writing Tests in Other Programming Languages
FitNesse executes wiki tables via Slim. If a Slim server is available for a language, you can use fixtures implemented in that language to write tests.

Communication between FitNesse and the Slim server takes place via socket communication or standard input/output.
For details of this protocol, refer to The Slim Protocol.
For Slim server support in different languages, refer to the official SLiM servers for different languages/environments (note: some implementations may be outdated).
It introduces Slim servers supporting various programming languages.
Testing Node.js with SlimJs
SlimJS is a Slim server for Node.js.
Its last update was six years ago, meaning it only supports Slim protocol v0.4 and socket communication only.
Additionally, fixtures must be written using an older JavaScript style.
Running the Sample
If the Docker containers are running, you can verify SlimJS operation at http://127.0.0.1:8080/FrontPage.SlimJs.
Click "Test" in the top menu to execute the test.


Fixture Examples
Place fixture files in /opt/fitnesse/slimjs_fixtures/.
These files implement test classes, but must use pre-ES5 syntax.
/opt/fitnesse/slimjs_fixtures/hello.js
function Hi(){
this.setEcho = function(str){
this.echo = str;
}
this.sayHi = function(){
return "Hi! " + this.echo;
}
}
module.exports.Hi = Hi;
/opt/fitnesse/slimjs_fixtures/calc.js
function Calc(){
this.setA = function(str){
this.a = Number(str);
}
this.setB = function(str){
this.b = Number(str);
}
this.add = function(){
return this.a + this.b;
}
}
module.exports.Calc = Calc;
Test Page
!define TEST_SYSTEM {slim}
!define SLIM_PORT {9086}
!define COMMAND_PATTERN {slimjs %p}
!path /opt/fitnesse/slimjs_fixtures
|import |
|hello|
Experimenting with tests using SlimJS
https://github.com/noamtcohen/SlimJS/tree/master
|Hi |
|echo |sayHi? |
|Bob |Hi! Bob |
|script |Hi|
|setEcho |Joe|
|show|sayHi?|
|check|sayHi?|Hi! Joe|
|import |
|calc|
|Calc |
|a |b |add? |
|1 |2 |3 |
|-1|2 |1 |
|0 |0 |0 |
Test configuration items:
-
SLIM_PORT: Specifies the port the Slim server will listen on. The Slim server waits for instructions from FitNesse on this port. It is safer to use a value greater than 1024. -
COMMAND_PATTERN: The command to runslimjs. Since SlimJS is installed globally,slimjsalone is sufficient. -
path: Specifies the path where fixtures are placed. The%ppassed toslimjsreceives this path, and the server searches for test fixtures within this folder.
import calc
Loads /opt/fitnesse/slimjs_fixtures/calc.js.
|Calc |
If no special instruction like script is given, it behaves like a data-driven table.
First, instantiate the Calc class.
|a |b |add? |
|1 |2 |3 |
|-1|2 |1 |
|0 |0 |0 |
This repeats the following process for each row:
setA(value of column a)setB(value of column b)- Compare the result of
add()with the value in column c
Modifying SlimJs
We modified SlimJs to add the following features:
- Communicate via standard input/output
- Allow writing fixtures using class syntax
Refer to the following for this implementation:
Fixture Examples
Place fixture files in /opt/fitnesse/slimjs_std/fixtures/.
Unlike the original SlimJs, you can use class syntax to create classes.
/opt/fitnesse/slimjs_std/fixtures/hello.js
export class Hi {
constructor(echo) {
this.echo = echo;
}
setEcho(str){
this.echo = str;
}
sayHi(){
return "Hi! " + this.echo;
}
}
/opt/fitnesse/slimjs_std/fixtures/calc.js
export class Calc {
constructor() {
this._a = 0
this._b = 0
}
setA(value) {
this._a = value;
}
setB(value) {
this._b = value;
}
add(){
return this._a + this._b;
}
}
Test Page
!define TEST_SYSTEM {slim}
!define COMMAND_PATTERN {/opt/fitnesse/slimjs_std/slim_std.js %p}
!path /opt/fitnesse/slimjs_std/fixtures
|import |
|hello|
Experimenting with tests using SlimJS
https://github.com/noamtcohen/SlimJS/tree/master
|Hi |
|echo |sayHi? |
|Bob |Hi! Bob |
|script |Hi|
|setEcho |Joe|
|show|sayHi?|
|check|sayHi?|Hi! Joe|
|import |
|calc|
|Calc |
|a |b |add? |
|1 |2 |3 |
|-1|2 |1 |
|0 |0 |0 |
The basic syntax is the same as with SlimJs.
The differences are as follows:
-
SLIM_PORTis no longer needed -
COMMAND_PATTERN: path changed -
path: path changed
Summary
This article summarized how to use FitNesse.
We introduced not only how to use existing Slim servers, but also how to create your own Slim server.
By leveraging this, it is still fully usable today.
However, since third-party Slim servers are not well maintained, it is advisable to thoroughly consider other options before adopting it for new projects.
For more detailed information, refer to the following pages:
Discussion