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 Case Action Argument Argument
Example Create File ${CURDIR}${/}input.data Some text here
  Set Environment Variable CLASSPATH ${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 Case Action Argument Argument Comment
Example 1A Connect example.com 80 # Connect gets two strings as arguments
Example 1B Connect example.com ${80} # Connect gets a string and an integer
Example 2 Do 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 Case Action Argument Argument
Example Should 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 Case Action Argument Argument Comment
Boolean Set Status ${true}   # Set Status gets Boolean true as an argument
  Create Y something ${false} # Create Y gets a string and Boolean false
None Do XYZ ${None}   # Do XYZ gets Python None as an argument
Null ${ret} = Get Value arg # 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 Case Action Argument Argument
One Space Should Be Equal ${SPACE} \ \
Four Spaces Should Be Equal ${SPACE * 4} \ \ \ \ \
Ten Spaces Should Be Equal ${SPACE * 10} \ \ \ \ \ \ \ \ \ \ \
Quoted Space Should Be Equal "${SPACE}" " "
Quoted Spaces Should Be Equal "${SPACE * 2}" " \ "
Empty Should 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

Variable Explanation 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

你可能感兴趣的:(Robotframework)