Automation One By One - 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 datafile is located. This variable is case-sensitive.
${TEMPDIR}An absolute path to the system temporary directory. In UNIX-likesystems this is typically/tmp, and in Windowsc:\Documents and Settings\<user>\Local Settings\Temp.
${EXECDIR}An absolute path to the directory where test execution wasstarted from. New in Robot Framework 2.1.
${/}The system directory path separator./in UNIX-likesystems,\in Windows.
${:}The system path element separator.:in UNIX-likesystems 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 inalphabetical order.Test case
${TEST STATUS}The status of the current test case, either PASS orFAIL.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 stringif 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 beenexecuted.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. Newin Robot Framework 2.5.Everywhere
${SUITE STATUS}The status of the current test case, either PASS orFAIL.Suite teardown
${SUITE MESSAGE}The full message of the current test suite, includingstatistics.Suite teardown
${OUTPUT FILE}An absolute path to the currentoutput file. Hasdifferent values during execution whenoutputs are split.Everywhere
${LOG FILE}An absolute path to the currentlog fileor stringNONE when no log file is created. Has different valuesduring execution whenoutputs are split.Everywhere
${REPORT FILE}An absolute path to thereport fileor string NONEwhen no report is created.Everywhere
${SUMMARY FILE}An absolute path to thesummary fileor string NONEwhen no summary is created.Everywhere
${DEBUG FILE}An absolute path to thedebug fileor string NONEwhen no debug file is created.Everywhere
${OUTPUT DIR}An absolute path to theoutput directory.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值