在黄瓜中参数化功能

时间:2020-01-28 21:59:18

标签: javascript cucumber gherkin

我遇到的情况是我的测试套件中的每个方案大纲都使用相同的参数集(我使用的是javascript):

Feature: Select a Product
  Install Checklist for Product

  Scenario Outline: functionA() is called on page type <type> -- No errors
    Given I load the site and go to a <type> page
    Then I should see no errors are thrown

    Examples:
      | type |
      | "product" |
      | "home" |
      | "collection" |

  Scenario Outline: functionA() is called on page type <type> -- Minimal delay
    Given I load the site and go to a <type> page
    Then there is a minimal delay before calling functionA()

    Examples:
      | type |
      | "product" |
      | "home" |
      | "collection" |

  Scenario Outline: functionA() is called -- correct type <type>
    Given I load the site and go to a <type> page
    Then the page type is <type>

    Examples:
      | type |
      | "product" |
      | "home" |
      | "collection" |

  ...many more tests using an identical Examples array

我正在寻求改进此代码的结构,而我看到的最好的方法是将Examples部分放在单个Scenario Outlines之外,作为全局参数。 。本质上,我希望使用Scenarios中的每个条目来运行每个Examples,而不必为每个Examples重复Scenario数组。我敢肯定,您会发现修改Examples数组将来会很麻烦。

在黄瓜中可以做到这一点吗?

类似的东西:

Feature Outline: Select a Product
  Install Checklist for Product

  Scenario Outline: functionA() is called on page type <type> -- No errors
    Given I load the site and go to a <type> page
    Then I should see no errors are thrown

  Scenario Outline: functionA() is called on page type <type> -- Minimal delay
    Given I load the site and go to a <type> page
    Then there is a minimal delay before calling functionA()

  Scenario Outline: functionA() is called -- correct type <type>
    Given I load the site and go to a <type> page
    Then the page type is <type>

  ...many more tests using an identical Examples array

  Examples:
    | type |
    | "product" |
    | "home" |
    | "collection" |

Feature: Select a Product
  Install Checklist for Product

  Rule Outline: verify functionA() on page type <type>

    Scenario Outline: functionA() is called on page type <type> -- No errors
      Given I load the site and go to a <type> page
      Then I should see no errors are thrown

    Scenario Outline: functionA() is called on page type <type> -- Minimal delay
      Given I load the site and go to a <type> page
      Then there is a minimal delay before calling functionA()

    Scenario Outline: functionA() is called -- correct type <type>
      Given I load the site and go to a <type> page
      Then the page type is <type>

  ...many more tests using an identical Examples array

    Examples:
      | type |
      | "product" |
      | "home" |
      | "collection" |

编辑:对于以后有兴趣的人,我在这里打开了一个相关的问题:https://github.com/cucumber/cucumber/issues/879

1 个答案:

答案 0 :(得分:1)

您可以尝试使用qaf-cucumber插件,该插件可以通过使用数据提供程序来重用示例。 BDD2 syntax

是对小黄瓜的扩展