从场景大纲的示例表中获取数据?

时间:2017-12-18 19:24:42

标签: c# specflow

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

1 个答案:

答案 0 :(得分: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
}