首页 > 解决方案 > 您可以使用参数/变量/占位符作为未来在 Specflow 场景中使用的值吗?

问题描述

在以前的工作中,我使用 DBFit 并使用参数(变量/占位符)作为值

例子:

|Key? |
|>>Key|

!|Query|SELECT Status FROM Confirm WHERE Name='xyz' |
| Status    | Key   |
| Confirmed | <<Key |

我现在正在使用 SpecFlow 并想知道它是否具有类似的功能

示例:(我在这里使用 << 和 >> 只是为了解释)

鉴于我得到 ​​Initial for 并且第一个响应应该包含

   | Name  | string | "xyz"     |
   | Key   | string | >>{Key}   |

当我得到确认时

那么第一个响应应该包含

   | Name  | string | "xyz"     |
   | Key   | string | <<{Key}   |

标签: specflow

解决方案


我认为您正在寻找方案大纲。

使用它们,您可以使用参数指定一个表。所以在你的情况下,它看起来像这样:

Scenario Outline: Title for your Scenario Outline

Given I get Initial for And the 1st response should contain 
| field | type   | assertion | 
| Name  | string | "xyz"     |
| Key   | string | <Key>     |

When I get Confirm for

Then the 1st response should contain 
| field | type   | assertion | 
| Name  | string | "xyz"     | 
| Key   | string | <Key>     |

Examples:
    | Key      |
    | example1 |
    | example2 |
    | example3 |

请注意,这里有两种不同类型的表。步骤中的表格是步骤的参数。最后的示例表是具体示例。因此,该表中的每个条目都会执行一次场景。

您可以将示例表中的参数与简单的 <COLUMN_NAME> 占位符一起使用。

文档:https ://docs.specflow.org/projects/specflow/en/latest/Gherkin/Gherkin-Reference.html#scenario-outline


推荐阅读