notpresent关键字在空手道中不起作用

时间:2019-02-24 11:26:02

标签: karate

我试图断定JSON响应中没有密钥。这是回应

   {
    "_type": "UserAccount",
    "accountName": "Account_Name",
    "accountType": "regular",
    "whiteList": true,
    "sfAccountId": "1",
    "preferredLanguage": "english",
    "imageSize": "highRes",
    "_id": "775a8451-6a07-42da-a199-fe98f44bdc06"
}

我已经根据karate#null-and-notpresent文档和Peter Thomas的答案尝试了这两个步骤

And match response.appClientId == '#notpresent'
And match response == {appClientId:'#notpresent'}

但这是我在上面第一步中遇到的错误

com.jayway.jsonpath.PathNotFoundException: No results for path: $['appClientId']

第二步

com.intuit.karate.KarateException: path: $, actual

预先感谢

1 个答案:

答案 0 :(得分:1)

也许您的版本已过时,以下内容在0.9.1中对我有用:

* def response =
"""
{
    "_type": "UserAccount",
    "accountName": "Account_Name",
    "accountType": "regular",
    "whiteList": true,
    "sfAccountId": "1",
    "preferredLanguage": "english",
    "imageSize": "highRes",
    "_id": "775a8451-6a07-42da-a199-fe98f44bdc06"
}
"""
* match response.appClientId == '#notpresent'
* match response contains { appClientId: '#notpresent' }