In Cucumber 'Feature file '-> 'Examples' , how to set path for CSV file

前端 未结 2 1185
余生分开走
余生分开走 2021-01-26 19:02

My sample feature file rather than giving data from Examples I want it to pass from csv how to achieve that can anyone help me out.

Feature file:

Feature         


        
2条回答
  •  感动是毒
    2021-01-26 20:02

    You can't with Gherkin. What you can do is to give your CSV file an appropriate name, refer to the name inside your Gherkin step, and then load and read the file inside your step definition.

    abc.feature

    Feature: A
      Scenario: 1
        Given data at abc.csv
        ...
    

    step-definitions.js

    Given(/^data at (.*)$/, function (fileName) {
      const data = jsonfile.readFileSync(`${__dirname}/${fileName}`);
      // iterate over data
    })
    

提交回复
热议问题