如何在数据驱动程序测试中为 Robot Framework 设置标签?

How to set tag for Robot Framework in data driver tests?

我正在尝试根据文档添加标签 https://github.com/Snooz82/robotframework-datadriver

这是我的例子:

*** Settings ***
Test Template  Template

*** Test Cases ***  ${first}  ${second}  [Tags]  [Documentation]
Test1               xxx       111        123 
Test2               yyy       222        126 
Test3               zzz       333        124 

*** Keywords ***
Template
    [Arguments]  ${first}  ${second}
    Should be true  ${TRUE}

但在这种情况下,我得到了错误:

Keyword 'Template' expected 2 arguments, got 3.

我也看到了这个解决方案:

但在这种情况下,我无法 运行 使用 -i test_tag

进行特定测试

欢迎。

您也可以像这样设置默认标签:

*** Settings ***
Default Tags    smoke

所有没有自己标签的测试用例都将收到定义为默认标签的标签。

或者你可以使用强制标签:

Force Tags      req-882

一个文件中的所有测试用例都会收到这样的标签。

但是,您的示例还存在另一个问题。您将 3 个参数传递给模板关键字,您的测试用例中有 3 列参数 table。应该是这样的:

*** Test Cases ***  ${first}    ${second}
Test1               xxx       111
Test2               yyy       222
Test3               zzz       333

所以整个工作示例:

*** Settings ***
Default Tags    smoke
Test Template  Template

*** Test Cases ***  ${first}    ${second}
Test1               xxx       111
Test2               yyy       222
Test3               zzz       333

*** Keywords ***
Template
    [Arguments]  ${first}  ${second}
    Should be true  ${TRUE}

当我 运行 $ robot --include smoke test.robot 时,我得到:

当我 运行 $ robot --exclude smoke test.robot 时,我得到:

编辑:

如果要为每个测试用例设置标签,语法为:

*** Test Cases ***  ${first}    ${second}
Test1               xxx       111
    [Tags]    smoke
Test2               yyy       222
Test3               zzz       333

在这种情况下,当您发出 $ robot -i smoke test.robot:

时,只会执行 Test1