Cucumber: Scenario Outline reusing examples table

我与影子孤独终老i 提交于 2019-12-02 02:09:24

The easiest solution that comes to my mind is combining both scenarios, extracting details to the examples table. So it would look like:

| number_1 | number_2 | operation | result |

You have another possibility.

Scenario: Add two numebrs
Given I have the matrix of numbers
When I add them
Then I would have the resulting vector.

Scenario: Update two numebrs
Given I have the matrix of numbers
When I update them
Then I would have the resulting vector.

Where "the matrix of numbers" and "the resulting vector" go to step defs file.

You can use qaf-gherkin where you can move examples in external file and use it with one or more scenario. With qaf your feature file may look like below:

Scenario Outline: Add two numebrs
  Given two numbers <number_1> and <number_2>
  When I add them
  Then Result is <number_3>

  Examples::{'datafile':'resources/testdata.txt'}

Scenario Outline: Update two numebrs
  Given two numbers <number_1> and <number_2>
  When I update them
  Then Result is <number_3>
  Examples:{'datafile':'resources/testdata.txt'}

And your datafile will look like:

  #col.separator=|
  number_1|number_2|number_3
  2|3|5       
  1|2|3       

Above is example of csv (charter separated values) data provider with | as seperator. You also can use different data providers to provide data from any of excel/xml/json/database.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!