content.txt 2.08 KB
!2 Defining and Expressing Variables.
You can define a variable to represent any amount of text.
 * Variable names may contain letters, numbers, and periods; e.g., MYTEST.someVar or user.name
 * You can define a variable in two ways: 
  * !style_code(!-!define var {text}-!) - as a delimited block of text 
  * !style_code[!-!define var othervar-!] - by copying the value of another variable 
 * The variable text can span many lines as shown below:
!style_code{!define myVariable {
This is the
text of my
variable
}}
!define myVariable {
this is the
text of my
variable
}

You express the value of a variable like this: !style_code{!-${myVariable}-!}.  This expression is replaced with the value of the variable.

''The value of the variable is: ${myVariable}.''

If the variable value contains wiki markup, it is interpreted as the variable is expressed.

!style_code{!-!define markedUp {This is '''bold'''}-!}
!define markedUp {This is '''bold'''}
!style_code{!-${markedUp}-!} is expressed as: ${markedUp}

A variable can reference other variables.

!style_code{!-!define y {y-value}-!}
!define y {y-value}
!style_code{!-!define x {The value of y is ${y}}-!}
!define x {The value of y is ${y}}
!style_code{!-${x}-!} is expressed as: ${x}
!style_code{!-!define y {new-y-value}-!}
!define y {new-y-value}
!style_code{!-${x}-!} is expressed as: ${x}

A variable can be copied from another variable.
!style_code{!-!define z y-!}
!define z y
!style_code{!-${z}-!} is expressed as: ${z}

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.

There are several [[pre-defined variables][<UserGuide.QuickReferenceGuide#VARIABLES]] that you can use on your pages.

See [[Variable fitnesse test][.FitNesse.SuiteAcceptanceTests.SuiteWidgetTests.TestVariables]], [[Parent Variable fitnesse test][.FitNesse.SuiteAcceptanceTests.SuiteWidgetTests.TestParentVariables]] and [[Define Variables in System Properties test][.FitNesse.SuiteAcceptanceTests.SuiteWidgetTests.TestVariablesFromSystemProperties]]