空手道数组字段从JS函数返回时成为对象 [英] Karate array field become object when it is returned from JS function
问题描述
我正在尝试将响应与JS函数生成的预定义JSON(预期)进行比较.
JS:
I'm trying to compare response with predefined JSON (expected) generated by JS function.
JS:
function(fleetId) {
var result = {};
result.name = "TestConnection";
result.fleetId = fleetId;
result.connectionConfigDefault = { "configParameters": [{ "keyName": "N/A", "value": "testValue" }], "id": 4 }
return result;
}
测试:
...
Then match connection.response ==
"""
{
connectionConfigDefault: '#(connectionJson.connectionConfigDefault)',
fleetId: '#(connectionJson.fleetId)',
id: '#number',
name: '#(connectionJson.name)'
}
"""
JS返回:
"connectionConfigDefault": {
"configParameters": { "0": { "keyName": "N/A", "value": "testValue" } }
}
而不是预期的:
"connectionConfigDefault": {
"configParameters": [{ "keyName": "N/A", "value": "testValue" }]
}
P.S.我阅读了类似的问题,但答案并没有帮助我解决问题. /p>
P.S. I read similar question, but the answer did not help me to solve the problem.
推荐答案
您可以做1件事.
在javascript中返回json之前,先使用configParameters = JSON.stringify(configParameters)
将其转换为字符串
现在从功能文件中使用json变量调用此函数.
you can do 1 thing..
before returning your json in javascript convert it to string using configParameters = JSON.stringify(configParameters)
now call this function from feature file, with json variable.
In function "function(fleetId)"
在返回结果之前,通过键入将其转换为字符串
before returning result convert it to string by typing
result = JSON.stringify(result)
在这里,您将从空手道中调用该函数
here you will call that function from karate
* json fleetId = function(fleetId)
* print fleetId
我希望这能解决您的问题
I hope this will resolve your question
这篇关于空手道数组字段从JS函数返回时成为对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!