Automated tests robot框架的[Documentation]中的Testcase级别变量

Automated tests robot框架的[Documentation]中的Testcase级别变量,automated-tests,robotframework,Automated Tests,Robotframework,我无法在文档中显示测试级别变量 假设我有这个测试套件: | *Variables* | | ${SystemUnderTest} = | Staging | *testcase* | | Device Test | | | Set Test Variable | ${device} | iPhone | | [Documentation] | Device is: ${device} | | | ... | System is: ${S

我无法在文档中显示测试级别变量

假设我有这个测试套件:

| *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
请注意,套件级别的变量处理正确,但测试级别的变量处理不正确。

如何平等对待所有变量?

这个解决方案让我觉得有点骇客,但它确实提供了您想要的功能

Test.txt 当我运行套件时,我得到以下输出:

==============================================================================
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
==============================================================================

在上一次测试结束时设置设备变量有点不干净,但只要您留下注释,就不会有任何不清楚的地方。

从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}

有关更多信息,请参见

如果我没有弄错的话,文档部分是在测试用例中处理之前处理的。这包括设置变量的任何类型的命令。我试着检查测试设置是否能做到这一点,但似乎连测试设置都是在测试用例的文档部分之后运行的。。。所以结果是一样的…谢谢你的投入。能够做到这一点将简化我的许多测试。嗯,这是一件很重要的事情。如果能够在控制台中跟踪事情,那还是很好的。非常感谢,但无法输出到控制台并不完美。
| *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}