如何在空手道中为 json 数组设置动态值
How to set a dynamic value for a json array in Karate
我有一个 json 文件,每个 post 请求都需要唯一值。 uniqId = '55555'。对于所有 uniq id,我需要传递相同的 uniqId。到目前为止,我只能设置 endtoEndid。无法设置 invoiceNum 和 txnValue。请帮忙。到目前为止,我已经完成了以下工作:
eval req = {"endtoEndid":"",
"prgrmId":"2344",
"invoices": [ { "invoiceNum":""}],
"currency":5.99,
"txnRefs": [ { "txnId":"name", "txnValue":""},{ "txnId":"state", "txnValue":"illinois"}]}
eval req['endtoEndId'] = 'endtoEnd' + uniqId。 (成功)
- eval req.invoices['invoiceNum'] = 'invoice' + uniqId(未成功)
- eval req['txnRefs.txnValue]'] = 'txn' + uniqId(未成功)
并请求 req
然后我尝试拆分:
- def reqInvoices = req.invoices
def reqTxnRefs = req.txnRefs[0]
eval reqInvoices['invoiceNum'] = 'invoice' + uniqId(未成功)
- eval reqTxnRefs['txnValue'] = 'txn' + uniqId(未成功)
并请求 req
我需要以下结果:
{"endtoEndid":"endToEndIduniqId",
"prgrmId":"2344",
"invoices": [ { "invoiceNum":"invoiceuniqId"}],
"currency":5.99,
"txnRefs": [ { "txnId":"name", "txnValue":"txnuniqId"},{ "txnId":"state", "txnValue":"illinois"}]}
谢谢
请尝试最新版本或0.9.6.RC3。
设置 JSON 现在更容易了,您不需要任何 eval
或 set
。
示例:
* def foo = {}
* foo.bar = 'baz'
* def random = function(){ return java.lang.System.currentTimeMillis() + '' }
* foo.ban = random()
* print foo
给出:
{
"bar": "baz",
"ban": "1591756622099"
}
我有一个 json 文件,每个 post 请求都需要唯一值。 uniqId = '55555'。对于所有 uniq id,我需要传递相同的 uniqId。到目前为止,我只能设置 endtoEndid。无法设置 invoiceNum 和 txnValue。请帮忙。到目前为止,我已经完成了以下工作:
eval req = {"endtoEndid":"", "prgrmId":"2344", "invoices": [ { "invoiceNum":""}], "currency":5.99, "txnRefs": [ { "txnId":"name", "txnValue":""},{ "txnId":"state", "txnValue":"illinois"}]}
eval req['endtoEndId'] = 'endtoEnd' + uniqId。 (成功)
- eval req.invoices['invoiceNum'] = 'invoice' + uniqId(未成功)
- eval req['txnRefs.txnValue]'] = 'txn' + uniqId(未成功) 并请求 req
然后我尝试拆分:
- def reqInvoices = req.invoices
def reqTxnRefs = req.txnRefs[0]
eval reqInvoices['invoiceNum'] = 'invoice' + uniqId(未成功)
- eval reqTxnRefs['txnValue'] = 'txn' + uniqId(未成功) 并请求 req
我需要以下结果:
{"endtoEndid":"endToEndIduniqId", "prgrmId":"2344", "invoices": [ { "invoiceNum":"invoiceuniqId"}], "currency":5.99, "txnRefs": [ { "txnId":"name", "txnValue":"txnuniqId"},{ "txnId":"state", "txnValue":"illinois"}]}
谢谢
请尝试最新版本或0.9.6.RC3。
设置 JSON 现在更容易了,您不需要任何 eval
或 set
。
示例:
* def foo = {}
* foo.bar = 'baz'
* def random = function(){ return java.lang.System.currentTimeMillis() + '' }
* foo.ban = random()
* print foo
给出:
{
"bar": "baz",
"ban": "1591756622099"
}