Karate 输入输出匹配的空手道问题
我可能遗漏了什么,但我注意到了一个琐碎的问题。我有一个来自JSON文件的被测端点的输入负载。以下是输入有效载荷:Karate 输入输出匹配的空手道问题,karate,Karate,我可能遗漏了什么,但我注意到了一个琐碎的问题。我有一个来自JSON文件的被测端点的输入负载。以下是输入有效载荷: { "KJ01": { "vin": "MMTestingVIN00001", "sskwngtrghastsp": "20200419133000", "wngdetail": [ { "wngsysmbol": "WASH", "wngc
{
"KJ01": {
"vin": "MMTestingVIN00001",
"sskwngtrghastsp": "20200419133000",
"wngdetail": [
{
"wngsysmbol": "WASH",
"wngclass": "S",
"wngcondflg": "1"
}
]
}
这是我得到的回应的一部分
{
"items": [
{
"vin": "MMTestingVIN00001",
"dealerCode": "1",
"nmscCode": "1",
"timestamp": "2020-04-19T13:30:00.000Z",
"warning": {
"warningLightType": {
"symbol": "WASH",
"type": "S",
"priority": "1"
}
}
}
]
}
响应包含items数组中的许多对象,我正在查找数组索引号,从中可以获得VIN=MMTestingVIN00001的对象
假设在items数组的索引10中找到了required response items对象
- def foundAt=10
* def Payload = read(datafile)
* json JsonPayload = Payload
# expecting WASH == WASH
* match response.items[foundAt].warning.warningLightType.symbol == JsonPayload.KJ01.wngdetail[0].wngsysmbol
这给了我一个错误:
Could not parse token starting at position 7. Expected ?, ', 0-9, *
但是当我在LHS的匹配表达式中明确提到索引10时
match response.items[10].warning.warningLightType.symbol == JsonPayload.KJ01.wngdetail[0].wngsysmbol
或者我用RHS交换LHS,这意味着如果我匹配了输入==输出,则不匹配输出==输入,即
match JsonPayload.KJ01.wngdetail[0].wngsysmbol == response.items[foundAt].warning.warningLightType.symbol
在上述两种情况下,它都有效
因此,作为结论,如果我们匹配outputexpression==inputexpression,其中outputexpression有一个arrayindex,该arrayindex由类似“foundAt”的变量引用,即它有一些类似于-items[foundAt],它不喜欢它并给出错误
在这种情况下,作为一种变通方法,当我们给出匹配inputexpression==outputexpression时,它就工作了
这里有我错过的一些琐碎的东西吗?我阅读了关于匹配表达式的LHS和RHS必须如何使用的文档,但无法使用这些信息来更改我的测试
有人能帮我吗?我希望我现在清楚了我的问题。请查看有关如何设置匹配语句左侧的文档。
这是正确的答案。但是有一个窍门!如果将LHS括在括号中,则可以对其强制求值:
*匹配(response.items[foundAt].warning.warningLightType.symbol)==foo