机器人框架的[文档]中的测试用例级别变量

时间:2013-02-07 13:54:18

标签: automated-tests robotframework

我无法让测试级变量出现在文档中。

假设我有这个测试套件:

| *Variables* |
| ${SystemUnderTest} = | Staging

| *testcase* |
| Device Test |
| | Set Test Variable   | ${device}      | iPhone
| | [Documentation]     |  Device is: ${device} |
| | ...                 |  System is: ${SystemUnderTest} |
| | No Operation

生成此日志:

TEST CASE: Device TestExpand All
Full Name:  T.Device Test
Documentation:  
Device is: ${device} System is: Staging

请注意,套件级别变量已正确处理,但测试级别1不是 如何让所有变量得到平等对待?

2 个答案:

答案 0 :(得分:4)

从robotframework 2.7开始,有一个名为Set test documentation的内置关键字,可用于替换或附加到现有文档。这将影响控制台中的输出,但更改反映在日志和报告中。

例如:

| *Variables* |
| ${SystemUnderTest} = | Staging

| *testcase* |
| Device Test |
| | Set Test Variable   | ${device}      | iPhone
| | [Documentation]     |  Device is: ${device} |
| | ...                 |  System is: ${SystemUnderTest} |
| | Substitute vars in documentation
| | No Operation

| *Keywords* |
| Substitute vars in documentation
| | ${doc}= | replace variables | ${test documentation}
| | set test documentation | ${doc}

有关详细信息,请参阅http://robotframework.googlecode.com/hg/doc/libraries/BuiltIn.html?r=2.7.7#Set%20Test%20Documentation

答案 1 :(得分:1)

这个解决方案让我觉得有点笨拙,但它确实为您提供了所需的功能。

Test.txt的

| *Setting*   | *Value*            |
              # This should start as the value for your first test
| Suite Setup | Set Suite Variable | ${device} | foo

| *Test Case* | *Action* | *Argument*
#
| T100 | [Documentation] | Should be foo: ${device}
       # Do some stuff
|      | No Operation
       # This setups the device name for the next test.
|      | Set Suite Variable | ${device} | bar 
#
| T101 | [Documentation] | Should be bar: ${device}
       # Do some stuff
|      | No Operation
|      | Set Suite Variable | ${device} | bing
#
| T102 | [Documentation] | Should be bing: ${device}
       # Do some stuff
|      | No Operation

当我运行套件时,我得到了这个输出:

==============================================================================
Test                                                                          
==============================================================================
T100 :: Should be foo: foo                                            | PASS |
------------------------------------------------------------------------------
T101 :: Should be bar: bar                                            | PASS |
------------------------------------------------------------------------------
T102 :: Should be bing: bing                                          | PASS |
------------------------------------------------------------------------------
Test                                                                  | PASS |
3 critical tests, 3 passed, 0 failed
3 tests total, 3 passed, 0 failed
==============================================================================

在上一次测试结束时设置设备变量有点不干净,但只要你发表评论,就不应该不清楚了。