Cucumber: Scenario Outline reusing examples table

后端 未结 3 731
予麋鹿
予麋鹿 2020-12-11 23:22

I have a few tests like below:

Scenario Outline: Add two numebrs
  Given two numbers  and 
  When I add them
  Then Result is         


        
3条回答
  •  遥遥无期
    2020-12-12 00:00

    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  and 
      When I add them
      Then Result is 
    
      Examples::{'datafile':'resources/testdata.txt'}
    
    Scenario Outline: Update two numebrs
      Given two numbers  and 
      When I update them
      Then Result is 
      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.

    EDIT: qaf-cucumber has BDD2 support with cucumber that can be used with Cumber 5.

提交回复
热议问题