Guide on the Script Table in FitNesse with an example

In “FitNesse For Beginners” tutorial series page, checkout all tutorials if you missed an article. In this table, we are going to discuss and learn about the slim testing engine using Script Table in FitNesse with an example in detail.

Script Table In FitNesse:

Script table is a series of actions and checks that are similar to Do Fixture. The first row of script table starts with word “Script” followed by the name of the fixture (known as the “actor”) and it’s constructor arguments that will be used by the rest of the table.

To work with the Library table, we need to do the following.

  • Syntactically, the Script table has the FitNesse reserved word “Script”. This word should be present in the first row and the first column of the table. The word “Script” in the table informs the slim processor which table type to execute.
  • The second column of the first row has the name of the fixture also known as an actor.
  • The third column, the fourth column and so on are the constructor arguments. Depending on the number of arguments the column number varies.
  • If there is no actor or fixture is specified for the script table then the previous script table’s actor on this test page will be used by the slim processor.
  • Alternately, the first cell for a script table can also be defined as shown below.

Script: script table | Appy | softtestclass

  • By default, the name of the function is assembled from tokens in every other cell. The arguments of the function are the intervening cells of the table. This is also known as Interposing Function Call. An example is shown below.

login with userID | Appy | and password | softtestclass

  • If we append “;” to the end of a function name in a cell, then it will invoke a sequential argument processing. It means that the arguments to the function are all subsequent cells. This is also known as Sequential Argument Processing Function Call.

login with userID and password;| Appy | softtestclass





Few Rules To Remember While Working With Script Table:

Below are the script table rules for the FitNesse slim testing engine.

  • In the script table, a function in a row will turn green or red if it returns a Boolean value (true or false). Otherwise, it will remain uncolored.
  • If the mention the word “check” in the first cell of a row, then a function call will follow it in the next cell. The last cell of the table is the expression will be matched by the value that the function actually returns as shown below.

check | login message received | Appy Successfully logged in.

  • If we do not mention the word “check” in the first cell of a row, then a function call will follow it in the next cell. The last cell of the table is the expression will be matched by the value that the function actually returns as shown below.
  • If we mention the word “ensure” in the first cell of a row, then it should be followed by a function in the next cell that should return a Boolean true for green and false for red.
  • If we mention the word “reject” in the first cell of a row, and then it should be followed by a function in the next cell that should return a Boolean false for green and true for red as shown below.

reject | login with userID | Appy | and password | bad password

  • If we mention the word “note “in the first cell of the row, all other following cells in that row will be ignored for processing by the slim processor as shown below.

note | This is a comment

  • If the first cell of a row is blank then all other following cells in that row will be ignored for processing by a slim
  • In case of the first cell of a row begins with Hash symbol (#) or asterisk (*) then all other following cells in that row will be ignored for processing by a slim
  • If we mention the word “show” in the first cell of a row, then it should be followed by a function call in the next cell of that row. A new cell will be added in the same row when the test is executed, and it will contain the return value of the function in that newly added cell as shown below.

show | number of login attempts made | 4

  • If we do a symbol assignment is in the first cell of a row, then it should be followed by a function in the next cell of that row. This symbol will be assigned a value which is returned by that function.

$symbol<-[Appy Successfully logged in.] | login message received

  • If we mention the word “start” in the first cell of a row, then the rest of the row is the name of the fixture or actor and its new constructor arguments, which replaces the existing actor.

Explanation for Java Fixture:

Like any ordinary Java fixture, it has the following members.

  • It has a class name as “ScriptTable”. Therefore, on the FitNesse page, it will be identified as “script table”.
  • It has a constructor which has two arguments. Here, they are userID and Password.
  • The first method of an actor known as “loginWithUserIDAndPassword” is a Boolean method that returns either true or false.
  • The second method is known as “loginMessageReceived” returns a string.
  • The third method is known as “numberOfLoginAttemptsMade” returns an integer value i.e. a number of login attempts made. This value is incremented over time we make a call to the actor from FitNesse test page.

Java Fixture class is shown below:

//Guide on the Script Table in FitNesse with an example
public class ScriptTable
{
private String userID;
private String password;
private String messageReceived;
private int loginAttemptsMade;

public ScriptTable(String userID, String password){
this.userID = userID;
this.password = password;
}

public boolean loginWithUserIDAndPassword(String userID, String password){
loginAttemptsMade++;
boolean result = this.userID.equals(userID) && this.password.equals(password);
if(result)
messageReceived = String.format("%s Successfully logged in.", this.userID);
else
messageReceived = String.format("%s loh in attempt Unsuccessful.", this.userID);
return result;
}

public String loginMessageReceived(){
return messageReceived;
}

public int numberOfLoginAttemptsMade(){
return loginAttemptsMade;
}
}

Screenshot for Script Table In FitNesse:

After we run the test on the script table, below the FitNesse screen will be visible.

#1) The Boolean method “loginWithUserIDAndPassword” called as Interposing Function Call has returned true, hence it is marked with green color on the page.

#2) The Boolean method “loginWithUserIDAndPassword” called as Sequential Argument Processing Function Call has returned true, hence it is marked with green color on the page.

#3) Check work is used with the method “loginMessageReceived” has returned the string “Appy Successfully logged in.” which matches the expected output. Hence, it is marked with green color on the page.

#4) Reject word is used with the method “loginWithUserIDAndPassword” called as Interposing Function Call which has an incorrect password and has returned false. It is marked with the red color on the page.

#5) Ensure word is used with the method “loginWithUserIDAndPassword” called as Interposing Function Call which has correct password and has returned true. It is marked with the green color on the page.

The note is a comment row which is simply ignored by the slim processor.

#6) Show word is used on method “number of login attempts made” which returned the count in an additional cell created in the same row.

Script Table in FitNesse
Fitnesse Tutorial For Beginners

⇓ Subscribe Us ⇓


If you are not regular reader of this website then highly recommends you to Sign up for our free email newsletter!! Sign up just providing your email address below:


 

Check email in your inbox for confirmation to get latest updates Software Testing for free.


  Happy Testing!!!
 

Leave a Comment

Share This Post