你可以在Karate中验证JSON响应的方式是什么?

huangapple go评论57阅读模式
英文:

How can I verify json response in Karate?

问题

[
{
"status": "COMPLETED",
"Greeting": "你好",
"API": "Rest"
}
]

现在我需要匹配响应的状态,看它是否是COMPLETED。

我尝试了以下方法,但没有成功。
并匹配 response.status == 'COMPLETED'。我可以这样做吗,还是我需要先存储这个响应?

并匹配 response.status == 'COMPLETED
并匹配 $ == {status:"FAILED"};

英文:

I have one response like below
Below is print response -
[print] [
{
"status": "COMPLETED",
"Greeting": "Hello",
"API": "Rest",
}
]

Now I need to match response status whether it is COMPLETED or not

I tried below things but is not working.
And match response.status == 'COMPLETED'. Can I do this or I need to store this response first ?

And match response.status == 'COMPLETED
And match $ == {status:"FAILED"}

答案1

得分: 1

尝试这样做:

  • 匹配 response[0].status == 'COMPLETED'
英文:

Tip: when you see a [] that is a JSON array.

Try this:

* match response[0].status == 'COMPLETED'

huangapple
  • 本文由 发表于 2023年7月10日 18:26:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76652852.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定