简体   繁体   English

如何从 excel 电子表格中读取输入数据并在空手道框架中传递 JSON 有效载荷?

[英]How to read input data from an excel spreadsheet and pass it JSON payload in karate framework?

I need to create data driven unit tests for different APIs in karate framework.我需要为空手道框架中的不同 API 创建数据驱动的单元测试。 The various elements to be passed in the JSON payload should be taken as input from an excel file.在 JSON 有效载荷中传递的各种元素应作为 excel 文件的输入。

A few points:几点:

  • I recommend you look at Karate's built-in data-table capabilities, it is far more readable, integrates into your test-script and you won't need to depend on other software.我建议您查看 Karate 的内置数据表功能,它更具可读性,集成到您的测试脚本中,您无需依赖其他软件。 Refer these examples: call-table.feature and dynamic-params.feature请参考以下示例: call-table.featuredynamic-params.feature
  • Next I would recommend using JSON instead of an Excel or CSV file, it is natively supported by Karate: call-json-array.feature接下来我建议使用 JSON 而不是 Excel 或 CSV 文件,空手道本身就支持它: call-json-array.feature
  • Finally, if you really wanted to, you can call any Java code and if you return data in a Map / List form, it will be ready for Karate to use.最后,如果您真的愿意,您可以调用任何 Java 代码,并且如果您以Map / List形式返回数据,它将可供空手道使用。 This example shows how to read a database via JDBC: dogs.feature .这个例子展示了如何通过 JDBC 读取数据库: dogs.feature So although this is not built into Karate, just write a simple utility to read a CSV or Excel file and you can do pretty much anything Java can do.因此,尽管这不是空手道内置的,但只需编写一个简单的实用程序来读取 CSV 或 Excel 文件,您就可以完成 Java 可以做的任何事情。

EDIT: Karate now supports CSV files that can be used to even do data-driven testing: https://github.com/intuit/karate#csv-files编辑:空手道现在支持 CSV 文件,甚至可以用来进行数据驱动测试: https ://github.com/intuit/karate#csv-files

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从一个特征文件表中读取数据并传递值以在空手道的 *.json 文件中设置 json 参数? - How to read data from one feature file table and pass the value to set json parameter in a *.json file in karate? 如何在空手道框架的特征文件中正确传递表单字段范围? - How to pass the form field scope correctly in feature file of karate framework? 如何在空手道框架的特征文件中读取响应头值? - how to read response header values in feature file of karate framework? 如何在空手道dsl中读取和编辑json文件并将其作为请求发送 - How to read and edit a json file and send it as a request in karate dsl 空手道 - 无法通过在空手道框架中使用 forEach 打印响应 json 的计数 - Karate - unable to print the count of the response json by using forEach in karate framework 如何从 cypress 中的 excel 读取数据 - How to read data from excel in cypress 如何从 cucumber 中的 excel 读取数据 - How to read data from excel in cucumber 如何检查空手道节点是否包含来自json响应的期望值 - How to check in karate if a node contains the expected value from the json response 如何参数化单个 Cucumber API 测试场景与空手道框架中的多个 Json 请求 - How to parametrise a single Cucumber API test Scenario with Multiple Json request in KARATE framework 如何在空手道框架中使用小黄瓜本地化? - How to use gherkin localization in Karate framework?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM