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

前端 未结 2 1143
余生分开走
余生分开走 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 19:54

    Not directly. However, you can have a record ID (or test case number) of sorts in the Example table. You can then retrieve records from the CSV in the step code based on the ID.

    Scenario Outline: Rocky Search Status with Filters
        Given Open firefox and start application for Rocky Search Status
        When User enters data specified in test case <tcn>
        Then Message displayed Rocky Search Status Successful
        Then Application should be closed after Rocky Search Status
    
        Examples: 
         |tcn|
         |1  |
         |2  |
    

    The "When" step will use the tcn to retrieve the corresponding record from the CSV.

    0 讨论(0)
  • 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
    })
    
    0 讨论(0)
提交回复
热议问题