4

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

假设我有这个测试套件:

| *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 没有。
如何让所有变量得到平等对待?

4

2 回答 2

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

于 2013-06-17T13:04:04.773 回答
1

这个解决方案对我来说有点骇人听闻,但它确实为您提供了您想要的功能。

测试.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
==============================================================================

在上一个测试结束时设置设备变量有点不干净,但只要你留下评论,它应该一点也不不清楚。

于 2013-06-13T14:49:02.563 回答