[英]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.