Robot Framework:在文档输出中显示测试用例的变量

Robot Framework: Show a variable of a test case in the documentation output

是否可以将我的测试用例的变量写入我的文档中?我不想打印全局变量!

*** Test Case ***
My Test Case
    [Documentation]    I want to print ${variable1} here.
    ${variable1}=    set variable    "hello, world"

因为以下是不可能的。

*** Test Case ***
My Test Case
    ${variable1}=    set variable    "hello, world"
    [Documentation]    I want to print ${variable1} here.

无法自动执行此操作,但您可以在使用关键字 Replace Variables and Set Test Documentation:

定义变量后的某个时刻在测试中动态设置文档
*** Test Case ***
Example
    [Documentation]    I want to print ${variable} here

    ${variable}=    set variable    "hello, world"

    ${doc}=    Replace variables    ${TEST DOCUMENTATION}
    set test documentation    ${doc}

请注意,这仅适用于出现在测试日志和报告中的文档。它不适用于 testdoc 工具,因为它显然要求测试已经执行。