7 Reference Common Functions - essenius/FitNesseFitSharpSupportFunctions GitHub Wiki

The Common Functions fixture contains functions that you may need quite frequently, such as date functions and evaluation functions, and some string functions such as Echo and Trim.

Add Days To
Description: Add a number of days to a date
In: number of days (double), date/time Out: new date offset by indicated number of days
Example: | add | 2.5 | days | to | today |
Note: days can contain fractions and can be negative
Add Hours To
Description: Add a number of hours to a date
In: number of hours (double), date/time
Out: new date offset by indicated number of hours
Example: | add | -1.5 | hours | to | now |
Note: Hours can contain fractions and can be negative
Calculate
Description: Calculate the result of a numerical expression
In: expression to be evaluated
Out: result of the evaluation (double)
Example: | check | calculate | 1/3 | ~=0.33 |
Note: Shorthand for Evaluate As with type double.
Concatenate
Description: Concatenate a list of values into a single string value
In: list of strings
Out: String containing the concatenated input strings
Example: | check | concatenate | [alpha, bet] | alphabet |
Date Format
Description: Get or set the default date format
In: date format to be used as default
Out: default date format currently in use
Example: | set date format | yyyy-MM-dd HH:mm:ss.ffffff |
|$format= | date format |
Note: Formatting follows the standard .Net conventions
Date Formatted
Description: Return a date using a specific format
In: date format to be used as default
Out: default date format currently in use
Example: | show | date | UtcNow | formatted | yyyy-MMM-dd |
Note: Formatting follows the standard .Net conventions
Echo
Description: Return the input parameter
In: input (can be any type)
Out: the input parameter
Example: |$fileName= | echo | test.json |
Note: Especially useful to initialize symbols.
Synonym: CloneSymbol (required by FitNesse to enable use of symbols in decision table results)
Evaluate [As]
Description: Evaluate an expression [and return the result as a specified type]
In: expression [, return type]
Out: the result of the evaluation
Example: | $var= | evaluate | 'abcd' + 'ef' |
| check | evaluate | substring('$var',1,2) | ab |
| check | len('$var') | 6 |
Supported types: bool, date, decimal, double, int, long, string, and the full names of standard .Net types as System.String, System.Int32, System.DateTime.
Supported operations: addition (+), subtraction (-), multiplication (*), division (/), and modulo (%).
Supported functions: LEN(expresssion), ISNULL(expression, replacement), IIF(expression, truevalue, falsevalue), TRIM(expression), SUBSTRING(expression, start , length)
Is True
Description: Evaluate a Boolean expression
In: expression
Out: true or false
Example: | ensure | is true | (true and not false) or false |
Note: Shorthand for Evaluate As with type bool.
Supported operations: AND, OR and NOT.
Supported comparisons: >, <, >=, <=, =, <>, IN, LIKE. For LIKE, wildcards (%, *) can be used at the beginning and/or end of the pattern. For IN, specify the values between parentheses, e.g. ′a′ IN (′a′, ′b′, ′c′)
Leftmost Of
Description: Return the leftmost characters of a string
In: number of characters, input string
Out: string containing leftmost part of the input
Example: check | leftmost | 5 | of | alphabet | alpha |
Parse
Description: Parse a string into a Date object
In: string representing a date/time value
Out: date object representing the input value
Example: | $SolarEclipse= |Parse | 21 Aug 2017 |
| $now= |Parse | now |
| $IndependenceDay= |Parse | 560295360000000000 |
Note: Today will return the current date (0:00 hours); Now will return current date and time. UtcToday will return the current date in UTC, and UtcNow will return the current date and time in UTC. If the input can be converted into a long, the input is assumed to be in Ticks (current time zone). Otherwise, the date should be an unambiguous date format. Safest is to use the sortable format (as per default)
Parse Formatted
Description: Parse a value into a Date using a specific date format
In: string representing a date/time value, string representing format to be used
Out: date object representing the input value
Example: | $SolarEclipse= |Parse|09/21/2017|formatted|MM/dd/yyyy |
Notes: If the date is not in the specified format, the function will throw a FormatException.
Date/time formatting follows the standard .Net convention.
Regex Escape
Description: Escape a string for literal use in Regex expressions (converts characters that need escaping)
In: string to be escaped
Out: escaped string
Example: |$escaped=|Regex Escape|c:\data\test.txt|
Note: $escaped would become c:\\data\\test\.txt
Regex Unescape
Description: Unescape a string uses in Regex expressions (converts escaped characters)
In: string to be escaped
Out: escaped string
Example: |$unescaped=|Regex Escape|c:\\data\\test\.txt|
Note: $unescaped would become c:\data\test.txt
Rightmost Of
Description: Return the rightmost characters of a string
In: number of characters, input string
Out: string containing rightmost part of the input
Example: check | rightmost | 3 | of | alphabet | bet |
Ticks
Description: Return the current ticks value
In: -
Out: long integer representing Ticks value
Example: | $nowTicks= | Ticks |
Note: Ticks are the number of 100-nanosecond intervals that have elapsed since midnight, January 1, 0001 (current time zone) in the Gregorian calendar. It will always return a unique higher value.
Ticks Between And
Description: Return the difference in ticks between two input dates
In: start date/time, end date/time
Out: long integer representing the elapsed time in Ticks
Example: | $TicksSinceMidnight= | Ticks Between | today | and | now |
Note: if the start date is after the end date, the result will be negative.
Ticks Since
Description: Return the difference in ticks between the input date and the current time.
In: start date/time
Out: long integer representing the elapsed time in Ticks
Example: | $TicksSinceMidnight= | Ticks Since | today |
Note: Shorthand for Ticks Between And with second parameter now
To Local
Description: Convert a UTC time to local time
In: date/time in UTC
Out: data/time in local time zone
Example: | $LocalDate= | To Local | $UtcDate |
To Ticks
Description: Return ticks value of the input date.
In: date/time
Out: long integer representing the date value in Ticks
Example: | check | To Ticks | $IndependenceDay | 560295360000000000 |
To Utc
Description: Return ticks value of the input date.
In: date/time in local time zone
Out: date/time in UTC
Example: | $UtcDate | To Utc | $LocalDate |
Trim
Description: Return string without leading or trailing whitespace.
In: string to be trimmed
Out: trimmed string
Example: | check | To Ticks | $IndependenceDay | 560295360000000000 |
Note: Can be useful if evaluations result in values with leading or trailing spaces, since FitNesse always expects trimmed strings to compare with.
Wait Seconds
Description: Wait the specified number of seconds
In: number of seconds to wait
Out: -
Example: | Wait | 0.5 | seconds |
Note: Should be a last resort, it’s typically better to wait on events (e.g. element appearance)
⚠️ **GitHub.com Fallback** ⚠️