How to match field value in response when there are multiple fields with the same name?

六月ゝ 毕业季﹏ 提交于 2020-08-10 20:14:26

问题


[
    {
        "key": "test1",
        "category": "test",
        "name": "test1",
        "translations": 
        {
            "english": "eng"
        }
    },
    {
        "key": "test2",
        "category": "test",
        "name": "test1",
        "translations": 
        {
            "english": "eng2",
            "german": "German"
        }
    },
    {
        "key": "test3",
        "category": "power",
        "name": "test1",
        "translations": 
        {
            "EN_lang": "jik"
        }
    }
]

Here, we have multiple field's are with different values and we have to match value in translations (field position will change on every call)


回答1:


You have to be clear about what you want to assert. Hint, the new contains deep (available in 0.9.6.RC4) can help:

* match response contains deep { key: 'test2', translations: { english: 'eng2' } }

Else you should look at transforming the JSON into a shape where it is easier to do the assertions you want: https://github.com/intuit/karate#json-transforms



来源:https://stackoverflow.com/questions/63103051/how-to-match-field-value-in-response-when-there-are-multiple-fields-with-the-sam

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!