Automation One By One - Robot Framework - 变量及赋值

上一篇 / 下一篇  2011-07-29 11:12:02 / 个人分类:Robot Framework

前面已经提到变量有三类,一类是scalar variable ${variable},一类是list variable,还有一类是内置(Built-in)的变量.

1. 给scalar variable类型的变量赋值:${scalar variable}

(1)${scalar variable}=  simple strings
(2)${scalar variable}=  objects
    无论scalar类型的变量被赋予什么值,这个值先被转换成Unicode,然后再按字符串显示出来。转换的过程相当于调用这个对象的__unicode__,__str__

2. 给list variable赋值: @{variable}

(1)列表变量中的值,可以是一个,也可以是多数(无数),还可以是空
(2)列表变量的值通常是字符类型的,其它类型的也可以
(3)可以通过@{NAME}[i]形式来访问列表中的某一个值
(4)可将list variables当作scalar类型的变量使用,使用方法是将list变量的符号从@替换成$就可以了;这种表达式让我们使用built-in类库及Collection类库中list相关的keywords成为可能。
(5)list变量可以应用在setting table中,但仅限于一部分的settings命令可用。
  • 对于Library及Resource的settings来说list变量不能作为其name使用,只能作为argument使用
  • 对于Setup/Teardown的settings来说list变量不能当作keyword的name使用,只能作为argument使用
  • 对于tag的settings来说可以随意使用
  • 对于不支持list变量的settings来说,我们可以使用scalar变量的形式来表达(如library及setup中的name不能使用list变量,我们可以用scalar变量代替list变量)
Using list variables with settings
SettingsValueValueComment
LibraryExampleLibrary@{LIB ARGS}# This works
Library${LIBRARY}@{LIB ARGS}# This works
Library@{NAME AND ARGS} # This does not work
Suite SetupSome Keyword@{KW ARGS}# This works
Suite Setup${KEYWORD}@{KW ARGS}# This works
Suite Setup@{KEYWORD} # This does not work
Default Tags@{TAGS} # This works


3. 给Envrionment Variables赋值:%{ENV_VAR_NAME}
(1)只能赋值string类型的值
(2)可于
OperatingSystem library类库中的keyword一块应用


4. 可以将keyword中返回的值作为变量存储

${keyword_return_value}=  Get Matching Xpath Count  [locator]
${keyword_return_value}=  Get Element Attribute  [locator]
...
5. 内置Build-in变量

Available operating-system-related built-in variables
VariableExplanation
${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 Windowsc:\Documents and Settings\<user>\Local Settings\Temp.
${EXECDIR}An absolute path to the directory where test execution was started from. New in Robot Framework 2.1.
${/}The system directory path separator./in UNIX-like systems,\in Windows.
${:}The system path element separator.:in UNIX-like systems and;in Windows.

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. New in Robot Framework 2.5.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 currentoutput file. Has different values during execution whenoutputs are split.Everywhere
${LOG FILE}An absolute path to the currentlog fileor string NONE when no log file is created. Has different values during execution whenoutputs are split.Everywhere
${REPORT FILE}An absolute path to thereport fileor string NONE when no report is created.Everywhere
${SUMMARY FILE}An absolute path to thesummary fileor string NONE when no summary is created.Everywhere
${DEBUG FILE}An absolute path to thedebug fileor string NONE when no debug file is created.Everywhere
${OUTPUT DIR}An absolute path to theoutput directory.Everywhere













TAG:

高山流水 引用 删除 love¥¥   /   2012-05-22 15:33:54
1
 

评分:0

我来说两句

Open Toolbar