RobotFramework内置变量:Built-in Variables(转载)

Built-in Variables

Robot Framework provides some built-in variables that are available automatically.

Operating System Variables

Built-in variables related to the operating system ease making the test data operating-system-agnostic.Available operating-system-related built-in variables:Variable Explanation${CURDIR} An absolute path to the directory where the test data file is located. This variable is case-sensitive.${TEMPDIR} An absolute path to the system temporary directory. In UNIX-like systems this is typically /tmp, and in Windows c:\Documents andSettings\\Local Settings\Temp.${EXECDIR} An absolute path to the directory where test execution was started from.${/} The system directory path separator. / in UNIX-like systems, \ in Windows.${:} The system path element separator. : in UNIX-like systems and ; in Windows.Using operating-system-related built-in variables
Test CaseActionArgumentArgument
ExampleCreate File${CURDIR}${/}input.dataSome text here
 Set Environment VariableCLASSPATH ${TEMPDIR}${:}${TEMPDIR}${/}foo.jar

Number Variables

The variable syntax can be used for creating both integers and floating point numbers, as illustrated in the example below. This is useful when a keyword expects to get an actual number, and not a string that just looks like a number, as an argument.Example:
Test CaseActionArgumentArgument Comment
Example 1AConnectexample.com80# Connect gets two strings as arguments
Example 1BConnectexample.com${80}# Connect gets a string and an integer
Example 2Do X${3.14}${-1e-4} # Do X gets floating point numbers 3.14 and -0.0001
It is possible to create integers also from binary, octal, and hexadecimal values using 0b, 0o and 0x prefixes, respectively. The syntax is case insetive.Example:
Test CaseActionArgumentArgument
ExampleShould Be Equal${0b1011}${11}
Should Be Equal${0o10}${8} 
Should Be Equal${0xff}${255} 
Should Be Equal${0B1010}${0XA}  

Boolean and None Variables

Also Boolean values and Python None can be created using the variable syntax similarly as numbers.Example:
Test CaseActionArgumentArgument Comment
BooleanSet Status${true} # Set Status gets Boolean true as an argument
 Create Ysomething${false}# Create Y gets a string and Boolean false
NoneDo XYZ${None} # Do XYZ gets Python None as an argument
Null${ret} =Get Valuearg# Checking that Get Value returns python none
 Should Be Equal${ret}${None}  
These variables are case-insensitive, so for example ${True} and ${true} are equivalent. Additionally, ${None} and ${null} are synonyms, because when running tests on the Jython interpreter, Jython automatically converts None and null to the correct format when necessary.

Space and Empty Variables

It is possible to create spaces and empty strings using variables ${SPACE} and ${EMPTY}, respectively. These variables are useful, for example, when there would otherwise be a need to escape spaces or empty cells with a backslash. If more than one space is needed, it is possible to use the extended variable syntax like ${SPACE * 5}. In the following example, Should Be Equal keyword gets identical arguments but those using variables are easier to understand than those using backslashes.Example:
Test CaseActionArgument Argument
One SpaceShould Be Equal${SPACE}\ \
Four SpacesShould Be Equal${SPACE * 4}\ \ \ \ \
Ten SpacesShould Be Equal${SPACE * 10}\ \ \ \ \ \ \ \ \ \ \
Quoted SpaceShould Be Equal"${SPACE}"" "
Quoted SpacesShould Be Equal"${SPACE * 2}"" \ "
EmptyShould Be Equal${EMPTY} \

Automatic Variables

Some automatic variables can also be used in the test data. These variables can have different values during the test execution and some of them are not even available all the time.Available automatic variables

VariableExplanation Available
${TEST NAME}The name of the current test case. Test case
@{TEST TAGS}Contains the tags of the current test case in alphabetical order. Test case
${TEST STATUS}The status of the current test case, either PASS or FAIL. Test teardown
${TEST MESSAGE}The possible error message of the current test case. Test teardown
${PREV TEST NAME}The name of the previous test case, or an empty string if no tests have been executed yet. Everywhere
${PREV TEST STATUS}The status of the previous test case: either PASS, FAIL or an empty string when no tests have been executed. Everywhere
${PREV TEST MESSAGE}The possible error message of the previous test case. Everywhere
${SUITE NAME}The full name of the current test suite. Everywhere
${SUITE SOURCE}An absolute path to the suite file or directory. Everywhere
${SUITE STATUS}The status of the current test case, either PASS or FAIL. Suite teardown
${SUITE MESSAGE}The full message of the current test suite, including statistics. Suite teardown
${OUTPUT FILE}An absolute path to the output file. Everywhere
${LOG FILE}An absolute path to the log file or string NONE when no log file is created. Everywhere
${REPORT FILE}An absolute path to the report file or string NONE when no report is created. Everywhere
${DEBUG FILE}An absolute path to the debug file or string NONE when no debug file is created. Everywhere
${OUTPUT DIR} An absolute path to the output directory. Everywhere

更多详情:https://twiki.cern.ch/twiki/bin/view/EMI/RobotFrameworkAdvancedGuide#Built_in_Variables

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值