如何从Excel电子表格中读取输入数据并在空手道框架中传递JSON有效负载? [英] How to read input data from an excel spreadsheet and pass it JSON payload in karate framework?

查看:89
本文介绍了如何从Excel电子表格中读取输入数据并在空手道框架中传递JSON有效负载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为空手道框架中的不同API创建数据驱动的单元测试.应当将JSON有效负载中传递的各种元素视为来自excel文件的输入.

I need to create data driven unit tests for different APIs in karate framework. The various elements to be passed in the JSON payload should be taken as input from an excel file.

推荐答案

几点:

  • 我建议您看一下Karate内置的数据表功能,它具有更高的可读性,可以集成到您的测试脚本中,并且您无需依赖其他软件.请参阅以下示例: dogs.feature .因此,尽管Karate并未内置此工具,但只要编写一个简单的实用程序即可读取CSV或Excel文件,您就可以完成Java可以做的几乎所有事情.
  • 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. Refer these examples: call-table.feature and dynamic-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
  • 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. This example shows how to read a database via 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.

这篇关于如何从Excel电子表格中读取输入数据并在空手道框架中传递JSON有效负载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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