【问题标题】:How to match field value in response when there are multiple fields with the same name?当有多个同名字段时,如何匹配字段值作为响应?
【发布时间】:2020-07-27 15:55:25
【问题描述】:
[
    {
        "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"
        }
    }
]

在这里,我们有多个字段具有不同的值,我们必须在翻译中匹配值(每次调用时字段位置都会改变)

【问题讨论】:

  • 总能得到一个索引值

标签: karate


【解决方案1】:

你必须清楚你想要断言什么。提示,新的contains deep(在 0.9.6.RC4 中可用)可以提供帮助:

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

否则,您应该考虑将 JSON 转换为更容易执行所需断言的形状:https://github.com/intuit/karate#json-transforms

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-26
    相关资源
    最近更新 更多