cucumber - Cucumber 中的可重用/通用示例表

标签 cucumber bdd gherkin cucumber-java qaf

是否可以多个场景使用同一个Examples表?

所以不要像下面这样:

Scenario Outline: First Scenario
    Given I am viewing "<url>"
    Then I assert that the current URL "<url>"
    Examples:
      | url                |
      | https://google.com |
      | https://twitter.com|

  Scenario Outline: Second Scenario
    Given I am viewing "<url>" with route "</contactus>"
    Then I assert that "<url>" contains "contactus"
    Examples:
      | url                |
      | https://google.com |
      | https://twitter.com|

我可以做类似的事情

Scenario Outline: Reusable Example
    Examples:
      | url                |
      | https://google.com |
      | https://twitter.com|

  Scenario: First Scenario
    Given I am viewing "<url>"
    Then I assert that the current URL "<url>"

  Scenario: Second Scenario
    Given I am viewing "<url>" with route "</contactus>"
    Then I assert that "<url>" contains "contactus"

我找到了一个 similar question on StackOverflow ,但将我的所有场景合并到一个场景中对我来说不是一个选择。由于这个问题是在 2014 年发布的,也许框架有一些我不知道的进步 :D

提前致谢。

最佳答案

您可以使用 qaf-gherkin您可以在其中移动外部文件中的示例并将其用于一个或多个场景。使用 qaf,您的功能文件可能如下所示:

Scenario Outline: First Scenario
   Given I am viewing "<url>"
   Then I assert that the current URL "<url>"
   Examples:{'datafile':'resources/testdata.txt'}

Scenario Outline: Second Scenario
Given I am viewing "<url>" with route "</contactus>"
Then I assert that "<url>" contains "contactus"
Examples:{'datafile':'resources/testdata.txt'}

您的数据文件将如下所示:

url
https://google.com
https://twitter.com

这是 reference .

关于cucumber - Cucumber 中的可重用/通用示例表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52168605/

相关文章:

java - 其他语言的 Cucumber lambda

java - cucumber 数据表错误 - io.cucumber.datatable.UndefinedDataTableTypeException : Can't convert DataTable to cucumber. api.DataTable

对现有项目进行 Python 单元测试以设置 BDD

Java-Maven- cucumber : Feature file is not able to run

cucumber - 是否有任何非开发人员工具来编辑小 cucumber 文件?

documentation - 如何从 Cucumber/Gherkin 生成文档?

c# - WatiN pressTab 不按 Tab

ruby - 如何使用 Cucumber 避免 "including Capybara::DSL in the global scope is not recommended!"?

php - 有哪些框架/工具/技术可以帮助从 PHP 运行 javascript?

ruby-on-rails - 如何使用 Cucumber 在页面中测试一个、多个或无图像?