Defining and Expressing Variables.
You can define a variable to represent any amount of text.- Variable names may contain letters, numbers, periods and underscores; e.g., MYTEST.someVar or user.name or USER_NAME
- You can define a variable in three ways:
- !define var {text} - as a delimited block of text
- !define var othervar - by copying the value of another variable
- !define var {${= 10 / 2 =}} - as an expression
- The variable text can span many lines as shown below:
This is the
text of my
variable
}
You express the value of a variable like this: ${myVariable}. This expression is replaced with the value of the variable.
The value of the variable is:
this is the
text of my
variable
.
If the variable value contains wiki markup, it is interpreted as the variable is expressed.
!define markedUp {This is '''bold'''}
${markedUp} is expressed as: This is bold
A variable can reference other variables.
!define y {y-value}
!define x {The value of y is ${y}}
${x} is expressed as: The value of y is y-value
!define y {new-y-value}
${x} is expressed as: The value of y is new-y-value
A variable can be copied from another variable.
!define z y
${z} is expressed as: new-y-value
A variable can contain an expression
!define n 10
!define q 2
!define d {${= ${n} / ${q} =}}
${d} is : 5
IMPORTANT: If the variables used in the expression change than also the result changes!
!define q 5
${d} is : 2
Variable Scope
If a variable is expressed on a page, but is not found, then its parent pages are searched in order.If the variable is not found in any ancestor pages, FitNesse will inspect System.properties.
Defining Variables In URL Input
You can define variables in the URL input by using the format of key=value (key as variable name & value as variable value). key and value can be any string values. Multiple variables can be specified separated by &.Variable values specified in the URL input are given precedence over variables defined on the page or in System.properties for the same key.
See Restful Services
Variables on included pages
- if you include a sub page into a main page than you can use the variables define on the main page also in the included pages.
- If you modify a variable on the sub page then the main page will also have the modified value.
- If you define a variable on the sub page you can reference it later on the main page.
Difference between variables and SLIM symbols
- Variables are evaluated at render time, before the test executes. This allows for values to be set based on page hierarchy and other things that are purely inputs to the tests.
- Symbols only exist at execution time. They can be changed at runtime, so are distinct from variables, which cannot.
Predefined Variables
There are several pre-defined variables that you can use on your pages.See Variable fitnesse test, Parent Variable fitnesse test, Define Variables in System Properties test and Variables, Symbols and Include pages