在 Cucumber '功能文件'->“示例",如何设置 CSV 文件的路径 [英] In Cucumber 'Feature file '-> 'Examples' , how to set path for CSV file

查看:20
本文介绍了在 Cucumber '功能文件'->“示例",如何设置 CSV 文件的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的示例功能文件,而不是提供示例中的数据,我希望它从 csv 传递如何实现,任何人都可以帮助我.

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: Rocky Search Status

      Scenario Outline: Rocky Search Status with Filters
        Given Open firefox and start application for Rocky Search Status
        When User enters "<price_right>" and "<Carat_left>" and "<Color_right_param>" and  "<Cut_right_param>" and "<Clarity_right_param>"
        Then Message displayed Rocky Search Status Successful
        Then Application should be closed after Rocky Search Status

        Examples: 
          | price_right | Carat_left | Color_right_param  | Cut_right_param |  Clarity_right_param |
          |       10000 |        1.5 |             80     |           180   |                84    |

我希望在项目外部以 CSV 格式定义数据值.

I want the data values to be defined in CSV outside the Project.

推荐答案

你不能用 Gherkin.您可以做的是给您的 CSV 文件一个适当的名称,在 Gherkin 步骤中引用该名称,然后在您的步骤定义中加载并读取该文件.

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
})

这篇关于在 Cucumber '功能文件'-&gt;“示例",如何设置 CSV 文件的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆