【问题标题】:How to set tag for Robot Framework in data driver tests?如何在数据驱动测试中为 Robot Framework 设置标签?
【发布时间】:2021-01-28 07:50:58
【问题描述】:

我正在尝试根据文档添加标签 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.

我也看到了这个解决方案:How to Tag Data Driven Template Tests in Robot Framework

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

【问题讨论】:

    标签: tags robotframework data-driven-tests


    【解决方案1】:

    欢迎。

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

    *** Settings ***
    Default Tags    smoke
    

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

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

    Force Tags      req-882
    

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

    但是,您的示例还包含另一个问题。您将 3 个参数传递给您的 Template 关键字,您的测试用例表中有 3 列参数。应该是这样的:

    *** 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:

    【讨论】:

    • 感谢您的回答。但是我需要为每个测试添加不同的标签。
    • 好的,我更新了我的答案,所以它符合您的要求。
    猜你喜欢
    • 2014-04-14
    • 1970-01-01
    • 2019-04-03
    • 1970-01-01
    • 2013-09-06
    • 2013-03-18
    • 2017-05-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多