2017-09-30
Variables初始化有三种方式:
Variables使用:
${VariableName}
示例1:
脚本如下:
!define markedUp {This is ‘‘‘bold‘‘‘}
${markedUp} is expressed as: This is bold
!define y {y-value}
!define x {The value of y is ${y}}
${x} is expressed as: The value of y is y-value
!define n {10}
!define q {2}
!define d {${=${n}/${q}=}}
${d} is : 5
!define q {5}
${d} is : 2
页面显示如下:

图1 示例1展示结果
当Variable在页面中被调用,但当前页面没有,fitnesse会去依次去父页面寻找,若祖先页面也没找到,fitnesse会去System.properties寻找
示例:
http://ip:port/ HelloWorld
http://ip:port/ HelloWorld.HelloWorld1
http://ip:port/ HelloWorld.HelloWorld2
当变量在included page中时:
示例2:
层次结构下:
Contents:
其中:
把其他页面include到father页面,来测试在不同关系中各个变量的使用范围,代码如下:
!define fatherMoney {80}
grandfaMoney is: ${grandfaMoney}
relativeMoney is: ${relativeMoney}
fatherMoney is: ${fatherMoney}
motherMoney is: ${motherMoney}
sonMoney is: ${sonMoney}
!include .Demo.variableIncludeTest.relative
!include .Demo.variableIncludeTest.grandfa.mother
!include .Demo.variableIncludeTest.grandfa.father.son
grandfaMoney is: ${grandfaMoney}
relativeMoney is: ${relativeMoney}
fatherMoney is: ${fatherMoney}
motherMoney is: ${motherMoney}
sonMoney is: ${sonMoney}
页面保存后展示如下图所示:

图2 include变量作用域展示结果
在图2中我们可以得知:
Symbol是在表中定义(赋值)和使用的
示例3:
wiki page脚本如下:
!define TEST_SYSTEM {slim} !path D:\fitnesseUtil\bin |import | |fitnesse.slim.test| |util| |script|Add|1|2.2| |$result=|calc| |check|calc|$result| |script|Add|$result|2.2| |$secondResult=|calc| |check|calc|$secondResult| |check|calc|$result|
其中:
执行结果:
图3 symbol(动态变量)的定义和使用
Symbol作用域:
示例4:
Contents:
grandfa页面脚本如示例3。father页面脚本如下:
!define TEST_SYSTEM {slim} !path D:\fitnesseUtil\bin |import | |fitnesse.slim.test| |util| |script|Add|1|2.2| |check|calc|$result| !include .Demo.variableIncludeTest.grandfa |script|Add|1|2.2| |check|calc|$result|
其中:
执行结果如下:

图4 symbol作用域
示例5:
脚本代码如下:
!define TEST_SYSTEM {slim} !path D:\fitnesseUtil\bin |import | |fitnesse.slim.test| |util| |script|Add|1|2.2| |$result=|calc| !define vResult {$result} vResult is: ${vResult} |script|Add|1|2.2| |check|calc|$result| |check|calc|${vResult}|
其中:
执行结果如下:

图5 把Symbol赋值给Variable
fitnesse - Variables and Symbols
原文:http://www.cnblogs.com/Ming8006/p/7615639.html