【问题标题】:Specflow - using data from external file in feature fileSpecflow - 在特征文件中使用来自外部文件的数据
【发布时间】:2022-02-24 14:09:16
【问题描述】:

我正在使用 SpecFlow 进行测试,并正在寻找一种在我的功能文件中使用来自 excel/csv/json 的输入数据的方法。我很喜欢使用 SpecFlow+ Excel,但它与我正在使用的 .NETCore 和 SpecFlow 3.3.57 不兼容。 我也尝试使用 Itamaram.Excel.SpecFlowPlugin 但它也没有用。 https://github.com/Itamaram/SpecFlow.Plugin.Base 有没有办法从外部文件读取输入数据并将其写入我的功能文件?

【问题讨论】:

标签: c# selenium bdd specflow import-from-excel


【解决方案1】:

我们有一个新插件可以从 json 文件中获取外部数据。

这是一个简单的 SpecFlow 插件,您可以将其安装为 NuGet package

使用示例:

@property:email=E-mail_addresses.Valid
Scenario Outline: recording user information on successful registration

Given a visitor registering as "Mike Scott" with email <email>
When the registration completes
Then the account system should record <email> related to user "Mike Scott"

Examples: key examples
  | Variant            | email              |
  | simple valid email | simple@example.com |

json 文件如下所示:

{ 
  "E-mail addresses": {
    "Valid" :{
      "Simple": "email@domain.com",
      "Dot in the address": "firstname.lastname@domain.com"
    }
  }
}

更多细节在博客文章中:https://specflow.org/blog/new-plugin-externaldata-helps-you-improve-test-coverage-quickly/


全面披露:我是 SpecFlow 和 SpecFlow+ 的社区经理

【讨论】:

    【解决方案2】:

    外部数据不适用于 SpecFlow 3.6 版本(构建应用程序的问题:错误缺少生成器插件)。外部数据适用于 3.9 版本,但此版本与 AfterScenario 挂钩存在问题。所有步骤都通过但最终测试失败(集合已修改;枚举操作可能无法执行)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-28
      • 2019-09-19
      相关资源
      最近更新 更多