How to read csv file based on scenario outline

2019-08-04 23:23发布

问题:

I am using cucumber and trying to read row from my csv file based on scenario name.

  Feature file :
    Scenario Outline: Verify content of my probblem1


Scenario,                       Title1, Title2, Title3, Title4, Title5
Verify content of my probblem1, Text1,  Text2,  Text3,  Text4,  Text5,
Verify content of my probblem2, Text1,  Text2,  Text3,  Text4,  Text5,

回答1:

The short answer is that reading CSV files from a Scenario written in Gherkin is not supported.

If you want to read data from an Excel file, you have to implement it yourself and call that functionality from your step. As @marit notices, Apache POI may be one option.



回答2:

The feature you are looking for is supported in gherkin with qaf. You can have examples in CSV/Excel/XML/json/DB

Scenario Outline: Search Keyword using data from file
When I search for "<searchKey>"
Then I get at least <number> results
Then it should have "<searchResult>" in search results

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

where your csv file may look like below:

searchKey,searchResult,number,TestCaseId
QMetry QAF, QMetry Automation Framework,15,TC-001
Selenium ISFW,Infostretch Test Automation Framework,45,111

You can refer documentation and step-by-step tutorial