【问题标题】:The notpresent keyword is not working in Karatenotpresent 关键字在空手道中不起作用
【发布时间】:2019-02-24 19:49:45
【问题描述】:

我试图断言某个键不在 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-notpresentPeter 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

提前致谢

【问题讨论】:

    标签: karate


    【解决方案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' }
    

    【讨论】:

    • 我们目前使用的是 v0.8.0 这个版本不支持这个功能吗?
    • @Ilan_p 我认为 0.9.0 中的一些错误修复与此有关
    • 以下步骤 * match response contains { appClientId: '#notpresent' } 可以满足我的需要,也不需要更新到 v 0.9.1
    猜你喜欢
    • 2021-03-24
    • 1970-01-01
    • 1970-01-01
    • 2021-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多