简体   繁体   English

空手道 DSL:如何将场景大纲变量传递到 json 字符串中

[英]Karate DSL: How to pass Scenario Outline variables into a json string

I'm testing a graphQL endpoint.我正在测试一个 graphQL 端点。 I want to keep the query separate from the feature file so that it can be reused elsewhere.我想将查询与功能文件分开,以便可以在其他地方重用。 The query has an embedded string which I want to pass in variables from my examples, however, I can't seem to update the query.该查询有一个嵌入的字符串,我想从我的示例中传递变量,但是,我似乎无法更新查询。

Here is the feature file:这是功能文件: 特征文件 Here is the query file:这是查询文件: 在此处输入图像描述

Any help would be appreciated, thanks.任何帮助将不胜感激,谢谢。

I think best practice is to read the query part alone as a text file, and then form the JSON within the test.我认为最佳做法是将查询部分单独读取为文本文件,然后在测试中形成 JSON。 Your JSON is actually not well-formed because JSON does not allow line-feeds within values, that's why you have the red squiggly line in your screen shot.您的 JSON 实际上格式不正确,因为 JSON 不允许在值内换行,这就是您的屏幕截图中有红色波浪线的原因。

Refer articles like this: https://www.katk.dev/graphql-karate参考这样的文章: https://www.katk.dev/graphql-karate

Best practice is to use the variables in the JSON in addition to the query .最佳实践是在query之外使用 JSON 中的variables If not, be aware that you can do placeholder substitution in plain-text using Karate: https://github.com/karatelabs/karate#replace如果没有,请注意您可以使用空手道在纯文本中进行占位符替换: https://github.com/karatelabs/karate#replace

Also read this part of the documentation: https://github.com/karatelabs/karate#dont-parse-treat-as-raw-text另请阅读文档的这一部分: https://github.com/karatelabs/karate#dont-parse-treat-as-raw-text

暂无
暂无

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

相关问题 空手道:是否可以从场景大纲中匹配 json - Karate: is it possible to match the json from scenario outline 在空手道场景大纲测试中,如何通过变量传递示例表中的参数值 - In Karate Scenario Outline test, how to pass param values in the Examples table through a variable 如何在空手道框架的场景大纲中添加“abortedStepsShouldPass”配置? - How to add 'abortedStepsShouldPass' configuration inside the scenario outline in Karate framework? 有没有办法为空手道 DSL 中的每个功能/场景分配一个唯一的“ID 密钥” - Is there a way to assign a unique “ID Key” to each feature/scenario in Karate DSL 如何在空手道特征文件中传递体型? - how to pass body type in Karate feature file? 无法识别在 csv 文件中存储和使用的用于空手道场景的 json 请求正文的正确格式 - Cannot identify proper format for a json request body stored and used in csv file for use in a karate scenario 如何在没有占位符的情况下更改空手道 DSL 中文本响应的所有外观? - How can you change all appearances of a text response in Karate DSL without having a placeholder? 如何通过 postman 将 JSON 字符串作为参数传递 - How to pass JSON string as parameter through postman 如何在空手道中将 Json Object 转换为 Json 数组? - How can I convert to Json Object to Json Array in Karate? 如何在空手道框架的post请求中传递多个参数? - How to pass multiple parameters in post request in karate framework?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM