9 Reference Other - essenius/FitNesseFitSharpSupportFunctions GitHub Wiki

Dictionary Library

Most functions operate on the internal fixture library that is used for persistence. Where that is the case, the description refers to ‘the’ dictionary. With functions that use a dictionary as parameter, the description refers to ‘a’ library.

Add Value [To]
Description: Add a key/value pair to a dictionary
In: key, value [, dictionary]
Out: -
Example: | Add | myKey | value | myValue | To | $myDictionary |
Note: Fails if the key/value pair already exists. Generally Set To In is preferred as more robust.
If To and the third parameter are omitted, the value is added to the dictionary.
Clear
Description: Delete all key/value pairs in the dictionary
In: [dictionary]
Out: -
Example: | Clear |
Count
Description: Return the number of key/value pairs in the dictionary
In: -
Out: the number of key/value pairs
Example: | Check | Count | 0 |
Delete File
Description: Delete a file
In: [path to file (absolute or relative)]
Out: whether or not successful
Example: | Delete File | MyDictonary.json |
Note: If the parameter is omitted, the default file is deleted. This function is useful when you use dictionaries for temporary storage.
Delete Page
Description: Delete a page under the page root
In: page name
Out: -
Example: | Delete Page | TestData |
Delete Table From Page
Description: Remove a data table from a page under the page root
In: table name, page name
Out: whether or not successful
Example: | Delete Table | Main | From | TestData |
File Name
Description: Set or get the filename used to load/save dictionaries
In: File Name to be used
Out: file name in use
Example: | Check | File Name | DictionaryStore.json |
Note: Can also be set implicitly via the Load and Save functions
Get [From]
Description: Get the value from a key/value pair in a dictionary
In: key[, dictionary]
Out: corresponding value
Example: | Check | Get | myKey | From | $myDictionary | myValue |
Note: If From and the second parameter are omitted, the get operation is done on the dictionary
Load File
Description: Load a dictionary file
In: [path to file (absolute or relative)]
Out: whether or not successful
Example: | Load File |
| Load File | MyDictionary.json |
Note: If the parameter is omitted, the default file is loaded.
Load Table From Page
Description: Load a data table from a page under the page root
In: table name, page name
Out: whether or not successful
Example: | Load Table | Main | From | TestData |
Note: The dictionary is cleared before the load, so if the operation fails, the dictionary is empty
Page Root
Description: Set or get the page root when using persistence to FitNesse pages
In: Page root to be used
Out: Page root in use
Example: | Set Page Root | http://localhost:8080/DataStore |
Remove [From
Description: Remove a key/value pair from the dictionary
In: key [,dictionary]
Out: -
Example: | Remove | MyKey |
Save File
Description: Save a dictionary to file
In: [file name]
Out: -
Example: | Save File |
| Save File | MyDictionary.json |
Note: If the parameter is omitted, the default file name is used.
Save Table To Page
Description: Save a data table onto a page under the page root
In: table name, page name
Out: -
Example: | Save Table | Main | To Page | TestData |
Set To [In]
Description: Set the value of a key/value pair in a dictionary
In: key, value [, dictionary]
Out: -
Example: | Set | myKey | To | myValue | In | $myDictionary |
Note: If the key/value pair doesn’t exist yet in the dictionary, it is added. Otherwise the value is updated. If In and the third parameter are omitted, the operation is done on the dictionary.
Wait For File
Description: Wait for a file to appear and become unlocked
In: [file name]
Out: whether or not successful before timeout
Example: | Wait For File |
Note: If the parameter is omitted, the default file is waited for. This function is useful when you use different processes that need to use the same file.

Machine Info

The Machine Info fixture provides basic information about the machine running the fixtures.

Fully Qualified Domain Name
Description: Return the FQDN of a machine, i.e. machine name with full domain.
In: [computer name]
Out: the FQDN
Example: | show | Fully Qualified Domain Name |
Note: if computer name is not specified, will take the current machine

Reflection Functions

The Reflection Functions fixture gives access to C# members (i.e. fields, properties or methods) of parameters and static classes via reflection.

Get [With Params][Of]
Description: Get the value of a member of an entity. If entity not specified, it expects a static class specification
In: member [,params][,entity]
Out: the value of the member
Example: | check | get | Substring(3,2) | of | abcdef | de |
| check |get | Int.MaxValue | 2147483647 |
| check | get | Math.Sqrt(49) | 7 |
| check | get | Math.Sqrt | of | 16.0 | 4 |
| check | get | Math.Sqrt | with params | [64] | 8 |
| check | get | Substring | with params | [3, 2] | of | abcdef | de |
Notes: No expressions are possible; it’s just getting the member values. If a method has no parameters, do not use parentheses (it would be interpreted as a parameter with an empty string)
Params are parameters for the method (in FitNesse array format)

Stopwatch

While FitNesse was designed for functional testing, it is also very well possible to measure performance of test steps, and e.g. make a test fail if it takes too long to run a scenario. For that, the Stopwatch fixture is available. It is most conveniently used as a library. You can use multiple stopwatches; they are identified by a string.

Read Stopwatch
Description: Return the elapsed time in seconds of a stopwatch
In: stopwatch ID (string)
Out: elapsed seconds (double)
Example: | check | read stopwatch | PerformanceTest1 | <1 |
Reset Stopwatch
Description: Reset a stopwatch to 0
In: stopwatch ID (string)
Out: -
Example: | reset stopwatch | PerformanceTest1 |
Restart Stopwatch
Description: Reset a stopwatch to 0 and start counting
In: stopwatch ID (string)
Out: -
Example: | restart stopwatch | PerformanceTest1 |
Start Stopwatch
Description: Start (or continue) a stopwatch
In: stopwatch ID (string)
Out: -
Example: | start stopwatch | PerformanceTest1 |
Stop Stopwatch
Description: Stop a stopwatch and return elapsed time in seconds
In: stopwatch ID (string)
Out: -
Example: | check | stop stopwatch | PerformanceTest1 | < 1 |

Test Control

Sometimes it makes sense to stop processing a test page, e.g. because an exception has occurred that makes it useless to continue. An example could be if you can’t reach the database containing the data you need to test with. That is why FitNesse supports the StopTestException. If a fixture throws that exception, it won’t run any further tests on the page. You can force a StopTestException via the Test Control functions. Similarly, FitNesse also supports the StopSuiteException which makes it ignore the rest of the currently executed suite.

Stop Suite If
Description: Throw a StopSuiteException if the parameter evaluates to true, or if it can’t be parsed as Boolean
In: -
Out: -
Example: | stop suite if | $condition |
Stop Suite If Not
Description: Throw a StopSuiteException if the parameter evaluates to false, or if it can’t be parsed as Boolean
In: -
Out: -
Example: | stop suite if not | $condition |
Stop Test If
Description: Throw a StopTestException if the parameter evaluates to true, or if it can’t be parsed as Boolean
In: -
Out: -
Example: | stop test if | $condition |
Stop Test If Not
Description: Throw a StopTestException if the parameter evaluates to false, or if it can’t be parsed as Boolean
In: -
Out: -
Example: | stop test if not | $condition |

User Info

The User Info fixture provides basic user information.

Display Name
Description: Return the current user’s display name
In: -
Out: the display name
Example: | show | Display Name |
User Name
Description: Return the current user’s user name
In: -
Out: the display name
Example: | show | User Name |
⚠️ **GitHub.com Fallback** ⚠️