我正在尝试利用空手道中的黄瓜功能将 Excel/csv 表作为示例部分中的文件传递空手、示例、黄瓜、道中

2023-09-07 23:49:32 作者:因为无能为力所以顺其自然

我正在尝试使用功能文件的场景大纲"部分下的示例".

I am trying to use "Examples" under "Scenario Outline" Section of a feature file.

在功能文件中,我尝试用以下格式表示它.这会按预期工作吗?

In Feature File, i tried representing it in the below format. Will this work as expected.

Feature: save data to db
Background: no definition
Scenario Outline: to validate file is getting read by example section

Given url 'https://www.googleapis.com/geolocation/v1/geolocate'
And param key = 'AIzaSyB2jt4BQ9McqBXAe8dYcp1CwKf0oGFlWuc'
And def dogs = read('classpath:external_table/json.feature')
And request { "homeMobileCountryCode": '<homeMobileCountryCode>' 
,"homeMobileNetworkCode": '<homeMobileNetworkCode>' } dogs
When method post
And print response
Then status 200

Examples: {'datafile':'src/test/java/external_table/testdata.xlsx'}

推荐答案

不,它不会按预期工作.正如其他人已经回答的那样,语法错误.

No it won't work as expected. As someone else has already answered, the syntax is wrong.

我不明白为什么在此处回答这个问题时你必须再次问这个问题:https://stackoverflow.com/a/49727819/143475

I don't understand why you have to ask this question again when it is answered here: https://stackoverflow.com/a/49727819/143475

也许您的领导坚持需要使用 Excel.根据经验,让我这么说,使用 Cucumber 原生示例或 Karate 的数据驱动功能要简单得多,您可以在其中循环 JSON 数组,请参阅:https://github.com/intuit/karate#the-karate-way

Maybe your leaders are insisting that Excel needs to be used. From experience let me say this, it is far simpler to use Cucumber native examples or Karate's data-driven capabilities where you can loop over a JSON array, refer this: https://github.com/intuit/karate#the-karate-way

如果你仍然坚持要使用 Excel,并且不愿意编写一个小的 Java 实用程序来将 Excel(或 CSV)转换为 JSON,那么请放弃使用空手道,它不是适合你的工具.一切顺利.

If you still insist that you want to use Excel and you are not willing to write a small Java utility to convert Excel (or CSV) to JSON, then please give up on using Karate, it is not the right tool for you. All the best.