【问题标题】:How to check in karate if a node contains the expected value from the json response如果节点包含来自 json 响应的预期值,如何检查空手道
【发布时间】:2017-09-27 21:27:03
【问题描述】:

场景是我得到了以下 JSON 响应,例如:

[
    {
        "a": "a",
        "b": "a",
        "c": "a",
    }
    {
        "a": "ab",
        "b": "ab",
        "c": "ab",
    }

]

现在我想检查响应是否在“b”节点中包含“ab”。 在空手道中,我不知道该怎么做。

给定路径'url' 当方法得到 然后状态 200 并匹配响应 == ??

【问题讨论】:

    标签: cucumber karate


    【解决方案1】:

    我建议您仔细阅读文档,空手道在这方面有很大的灵活性。下面是一些示例,您可以将它们粘贴到您的 *.feature 文件中,然后看看它们是否适合您自己:

    * def response =
    """
    [
        {
            "a": "a",
            "b": "a",
            "c": "a",
        },
        {
            "a": "ab",
            "b": "ab",
            "c": "ab",
        }
    ]
    """
    * match response[1] contains { b: 'ab' }
    * match response contains { a: 'ab', b: 'ab', c: 'ab' }
    * match response contains { a: '#ignore', b: 'ab', c: '#notnull' }
    * def expected = { b: 'ab' }
    * match response contains '#(^expected)'
    

    【讨论】:

      猜你喜欢
      • 2020-12-03
      • 1970-01-01
      • 2018-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-27
      • 1970-01-01
      • 2021-11-17
      相关资源
      最近更新 更多