【问题标题】:How do you add tags to data-driven tests in Robot Framework?如何在 Robot Framework 中为数据驱动的测试添加标签?
【发布时间】:2014-04-14 10:05:29
【问题描述】:

我正在尝试向 Robot Framework 中的数据驱动测试添加标签。我为模板化测试和数据表创建了关键字,类似于以下内容:

# Test case file
*** settings ***
Resource       libraries.txt
Test Template  My Test Template

*** test cases ***       parameter1   parameter2  ER
testa                    value1a      value2a     ERa
testb                    value1b      value2b     ERb

# Template file
*** Keywords ***
My Test Template
  [Arguments]  ${parameter1}  ${parameter2}  ${ER}
  ${result}=  Do Something  ${parameter1}  ${parameter2}
  Should Be Equal As Strings  ${result}  ${ER}

如何为 testa 和 testb 添加(可能不同的)标签?


原来是PEBKAC。我没有缩进标签语句。那些双空格让我(再次)进入。

【问题讨论】:

    标签: robotframework


    【解决方案1】:

    标签可以这样添加:

    *** test cases ***       parameter1   parameter2  ER
    testa                    value1a      value2a     ERa
        [Tags]    tag1
    testb                    value1b      value2b     ERb
        [Tags]    tag1
    

    【讨论】:

    • 天啊!通过那些讨厌的缩进完成。我在测试名称下方有方括号,而不是两个空格。
    【解决方案2】:

    添加标签的方法有多种。

    只有特定的测试是这样的:

    *** Test cases ***
    Test A
      [tags] tagA tagB
      Log  This is test A
    

    可以通过在设置中放置Force Tags 来为文件中的所有测试用例添加标签:

    *** Settings ***
    Force Tags  NewTag
    

    有关更多信息,您可以查看用户指南:http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#tagging-test-cases

    【讨论】:

    【解决方案3】:

    一种解决方案是修改您的关键字以将标签作为参数。然后你可以这样做:

    *** Settings ***
    | Test Template | My Test Template
    
    *** test cases ***       
    | testa | value1a  | value2a | ERa | tag1 | tag2
    | testb | value1b  | value2b | ERb | tag2 | tag3
    
    *** Keywords ***
    | My Test Template
    | | [Arguments] | ${value1} | ${value2} | ${er} | @{tags}
    | | log | value1: ${value1}
    | | log | value2: ${value2}
    | | log | er: ${er}
    | | Set tags | @{tags}
    

    运行时,testa 将具有标签tag1tag2,而testb 将具有标签tag2tag3

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-03
      • 1970-01-01
      • 2017-05-08
      • 2015-07-19
      • 2013-03-18
      • 2013-09-24
      • 2014-10-01
      相关资源
      最近更新 更多