空手道:从JSON文件中的嵌入式表达式动态输入值 [英] Karate : Dynamically input values from embedded expressions in a JSON file
本文介绍了空手道:从JSON文件中的嵌入式表达式动态输入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
* def mpRequestJson =
"""
{
"entity": '<entity>',
"consent": {
"PHONE": <updategetPhonePref>,
"EMAIL": true,
"POST": false,
"SMS": <updategetSMSPref>
},
"notices": [{
"title": "Privacy policy",
"version": "NA"
}],
"source": "web"
}
"""
Given path '<entity>'
And request mpRequestJson
When method PUT
Then status 200
And match $.consent.PHONE == '<updategetPhonePref>'
And match $.consent.SMS == '<updategetSMSPref>'
Examples:
|entity | updategetPhonePref|updategetSMSPref|
|xyz| #(updategetPhonePref)|#(updategetSMSPref)|
如果我想将JSON请求存储在JSON文件而不是功能文件中,那么我的JSON文件应该是什么?
If i want to store the JSON request in a JSON file rather than in the feature file, what should be my JSON file?
推荐答案
在JSON中使用嵌入表达式,例如
In the JSON use embedded expressions, e.g.
entity: '#(entity)'
然后您可以从文件中读取它:
Then you can read it from a file:
* def mpRequestJson = read('my.json')
但是在read
之前,您应该初始化必须替换的变量.因此,您将有一些额外的行.
But before the read
you should initialize variables that have to be substituted. So you will have some extra lines.
* def entity = '<entity>'
减少多余行数的一种方法是创建临时JSON:
One way to reduce the extra lines is to create a temp JSON:
* def data = { entity: '<entity'>, phone: '<updategetPhonePref>' }
然后您可以在JSON中完成此操作:
And then you can do this in the JSON:
entity: '#(data.entity)'
还请阅读数据驱动测试上的文档.
这篇关于空手道:从JSON文件中的嵌入式表达式动态输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文