【问题标题】:Using a background step like an Outline Step使用像大纲步骤这样的背景步骤
【发布时间】:2020-03-18 10:21:48
【问题描述】:

我希望能够为文件中的每个场景定义一组运行规则。最容易放置这些内容的地方是在后台,但他们需要有一个非常类似于场景大纲的示例表。

    Feature: Example Feature File
    In order to perform as task 
    As I user 
    I want this test to work 

Background: 
 Given I have used <data> in my test 
 Examples: 
 | data           | 
 | test string    | 
 | test String  2 | 


Scenario Outline: Running a test
Given I have prepared the test data 
When I run the test 
Then The test should pass 

任何人都可以想出一种方法来完成这项工作(或类似的东西),因为我已经进行了 200 多个测试并且我有点讨厌将其添加到每个测试中

【问题讨论】:

  • 不幸的是,您需要将其放在每个场景中。您不能为背景提供示例数据。

标签: c# .net automation specflow


【解决方案1】:

不幸的是,您需要将其放在每个场景中。您不能为背景提供示例数据。

【讨论】:

    【解决方案2】:

    一种方法是在后台使用createSetcreateInstance。如果表中有数据,可以使用assist helpers。它们都支持表结构,你可以在Background中使用它们

    另一种方法是在Beforescenario hook 中实现上表。您可以使用tag scoping 进一步分类

    在这两种情况下,您都必须使用属性或上下文或其他方式来实现传递数据。你可以阅读featureContext

    在实施时,请记住虽然Background 将在每个场景的第一步之前运行,但在任何Before 挂钩之后运行

    Imo,它仍然值得实现,即使它比在每个场景中都包含数据需要更多的努力。

    【讨论】:

      猜你喜欢
      • 2018-07-25
      • 1970-01-01
      • 2017-03-28
      • 1970-01-01
      • 2016-02-13
      • 2016-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多