首页 > 解决方案 > 空手道 DSL - 使用重试直到检查数组,直到所有项目中都存在特定的键值对

问题描述

所以我有一个与下面的示例结构类似的响应。Key2 最终将更改为一个值,这意味着我的测试可以继续,所以我想通过使用重试直到确保 Key2 的所有值最终都是“测试”。我试图按照文档来做一些事情,但运气不佳。

{
    "Array": [

        {
            "Key1": "Value1",
            "Key2": "Test"
        },
        {
            "Key1": "Value1",
            "Key2": "Test"
        }
    ]
}

任何帮助都会很棒。谢谢你。

解决方案:

And retry until karate.match("each response.Array contains { Key2: 'Test' }").pass

标签: karatescenarios

解决方案


试试这个,了解它是如何工作的,然后你就会知道该怎么做:

* def response = 
"""
{
    "Array": [
        {
            "Key1": "Value1",
            "Key2": "Test"
        },
        {
            "Key1": "Value1",
            "Key2": "Test"
        }
    ]
}
"""
* def result = karate.match("each response..Key2 == 'Test'")
* assert result.pass

推荐阅读