Automation One By One - Robot Framework - 变量及赋值
2011-10-20 17:09
525 查看
前面已经提到变量有三类,一类是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
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
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变量)
Settings | Value | Value | Comment |
---|---|---|---|
Library | ExampleLibrary | @{LIB ARGS} | # This works |
Library | ${LIBRARY} | @{LIB ARGS} | # This works |
Library | @{NAME AND ARGS} | # This does not work | |
Suite Setup | Some Keyword | @{KW ARGS} | # This works |
Suite Setup | ${KEYWORD} | @{KW ARGS} | # This works |
Suite Setup | @{KEYWORD} | # This does not work | |
Default Tags | @{TAGS} | # This works |
(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变量
Variable | Explanation |
---|---|
${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. |
Variable | Explanation | Available |
---|---|---|
${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. |
相关文章推荐
- Automation One By One - Robot Framework - Test Suite
- Automation One By One - Robot Framework - Keyword/Variable Files
- Automation One By One - Robot Framework - 数据类型
- Automation One By One - Robot Framework - 优化Test Case
- Automation One By One - Robot Framework - User Keywords
- Robot Framework--07 变量的声明、赋值及其使用
- 机器学习 Machine Learning(by Andrew Ng)----第二章 单变量线性回归(Linear Regression with One Variable)
- 联合变量的赋值和使用
- MySql 申明变量以及赋值
- ajax给全局变量赋值问题
- rowtype类型变量可直接赋值
- shell编程之给变量赋值的五种方法
- 找了好久:awk 赋值给 shell 变量的方法
- 嵌入式 给变量赋值为空格
- Workplan Structure Locked By One User, Can be Unlocked By Another
- C 语言三目运算符 max = (a > b) ? a : b ; // 取变量a,b中较大一个,并赋值给变量max
- GO语言学习日记(五)GO语言变量与赋值
- C语言变量赋值问题
- Expected one result (or null) to be returned by selectOne(), but found: 2
- C/C++ 通过初始化列表和构造函数内赋值初始化成员变量的区别