Reputation: 511
I may be missing something but there is a trival issue I am noticing. I have an input payload to an endpoint under test that comes from a JSON file. Here is the input payload:
{
"KJ01": {
"vin": "MMTestingVIN00001",
"sskwngtrghastsp": "20200419133000",
"wngdetail": [
{
"wngsysmbol": "WASH",
"wngclass": "S",
"wngcondflg": "1"
}
]
}
And this is the part of the response I get
{
"items": [
{
"vin": "MMTestingVIN00001",
"dealerCode": "1",
"nmscCode": "1",
"timestamp": "2020-04-19T13:30:00.000Z",
"warning": {
"warningLightType": {
"symbol": "WASH",
"type": "S",
"priority": "1"
}
}
}
]
}
The response contains many objects in the items array and I am finding the array index number where I get the object with VIN = MMTestingVIN00001 So lets say the required response items object was found at index 10 in the items array.
When I do the following:
* def Payload = read(datafile)
* json JsonPayload = Payload
# expecting WASH == WASH
* match response.items[foundAt].warning.warningLightType.symbol == JsonPayload.KJ01.wngdetail[0].wngsysmbol
it gives me an error:
Could not parse token starting at position 7. Expected ?, ', 0-9, *
But when I explictly mention the index no 10 in my match expression on LHS i.e
match response.items[10].warning.warningLightType.symbol == JsonPayload.KJ01.wngdetail[0].wngsysmbol
or I swap LHS with RHS, meaning instead of match output == input, If I do match input == output i.e
match JsonPayload.KJ01.wngdetail[0].wngsysmbol == response.items[foundAt].warning.warningLightType.symbol
in both above cases it works.
So as a conclusion, if we do a match outputexpression == inputexpression where the outputexpression has an arrayindex referenced by a variable like 'foundAt' ie it has something like - items[foundAt], it does not like it and gives the error.
As a workaround in such cases, when we give match inputexpression == outputexpression then it works.
Is there something trival that I am missing here? I read the documentation on how the LHS and RHS of match expressions have to be but wasn't able to use that information to change my tests.
Can someone help me please? I hope I am now clear with my issue.
Upvotes: 1
Views: 434
Reputation: 1096
Please look at the documentation on how the left-hand-side of the match statement has to be setup. https://github.com/intuit/karate#match-and-variables
Upvotes: 2