如何根据场景大纲读取csv文件

问题描述 投票:0回答:2

我正在使用黄瓜并尝试根据场景名称从 csv 文件中读取行。

  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,
cucumber cucumber-java cucumber-serenity
2个回答
0
投票

简短的回答是不支持从用 Gherkin 编写的场景中读取 CSV 文件。

如果您想从 Excel 文件读取数据,您必须自己实现并从您的步骤中调用该功能。正如@marit 所注意到的,Apache POI 可能是一种选择。


0
投票

您正在寻找的功能在 gherkin 和 qaf 中得到支持。您可以在 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'}

您的 csv 文件可能如下所示:

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

您可以参考文档分步教程

© www.soinside.com 2019 - 2024. All rights reserved.