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

来源:互联网 发布:网络打印机ip地址查询 编辑:程序博客网 时间:2024/06/06 01:42

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 variablesTest CaseActionArgumentArgumentExampleCreate 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 CaseActionArgumentArgumentCommentExample 1AConnectexample.com80# Connect gets two strings as argumentsExample 1BConnectexample.com${80}# Connect gets a string and an integerExample 2Do X${3.14}${-1e-4}# Do X gets floating point numbers 3.14 and -0.0001It 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 CaseActionArgumentArgumentExampleShould 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 CaseActionArgumentArgumentCommentBooleanSet Status${true} # Set Status gets Boolean true as an argument Create Ysomething${false}# Create Y gets a string and Boolean falseNoneDo XYZ${None} # Do XYZ gets Python None as an argumentNull${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 CaseActionArgumentArgumentOne 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

VariableExplanationAvailable${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 0
原创粉丝点击