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;
}
Test:
...
Then match connection.response ==
"""
{
connectionConfigDefault: '#(connectionJson.connectionConfigDefault)',
fleetId: '#(connectionJson.fleetId)',
id: '#number',
name: '#(connectionJson.name)'
}
"""
JS return:
"connectionConfigDefault": {
"configParameters": { "0": { "keyName": "N/A", "value": "testValue" } }
}
instead of expected:
"connectionConfigDefault": {
"configParameters": [{ "keyName": "N/A", "value": "testValue" }]
}
P.S. I read similar question, but the answer did not help me to solve the problem.
Yes there is this weird bug in the JDK that you normally never run into unless you start doing nested arrays in JS: https://github.com/intuit/karate/blob/master/karate-junit4/src/test/java/com/intuit/karate/junit4/demos/js-arrays.feature#L44
The workaround here is to do JSON construction using Karate not JS:
EDIT: see using
read()
below, instead of "in-line":Since Karate has so many nice ways, why don't you use those:
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.before returning result convert it to string by typing
here you will call that function from karate
I hope this will resolve your question