【问题标题】:Get data from Examples table on scenario outline?从场景大纲的示例表中获取数据?
【发布时间】:2017-12-18 19:24:42
【问题描述】:

在使用场景大纲格式时,specflow 是否提供了一种从“示例”表中获取数据的方法?类似于标签在执行期间如何在场景上下文中可用。

【问题讨论】:

    标签: c# specflow


    【解决方案1】:

    不,没有办法。

    您写入示例表的示例类似于场景的参数。 这些值替换场景步骤中的占位符(它们在 括号中)

    Gherkin 文档中的示例(https://cucumber.io/docs/reference - 场景大纲)

    Scenario Outline: feeding a suckler cow
      Given the cow weighs <weight> kg
      When we calculate the feeding requirements
      Then the energy should be <energy> MJ
      And the protein should be <protein> kg
    
      Examples:
        | weight | energy | protein |
        |    450 |  26500 |     215 |
        |    500 |  29500 |     245 |
        |    575 |  31500 |     255 |
        |    600 |  37000 |     305 |
    

    如果您使用数据表作为参数,则只能获取整个表。 示例:

    Given the following users exist:
      | name   | email              | twitter         |
      | Aslak  | aslak@cucumber.io  | @aslak_hellesoy |
      | Julien | julien@cucumber.io | @jbpros         |
      | Matt   | matt@cucumber.io   | @mattwynne      |
    

    您可以使用此绑定访问它:

    [Given(@"the following users exist:")
    public void TheFollowinUsersExists(Table table)
    {
        //your code
    }
    

    【讨论】:

    • 感谢您的快速发帖!我的目标是在作用域 beforeEach 块中使用这些数据。如果有人有任何好主意,欢迎解决。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-09
    • 2014-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-04
    相关资源
    最近更新 更多