首页 文章

如果节点包含来自json响应的期望值,如何检入空手道

提问于
浏览
1

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

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

]

现在我想检查响应是否在“b”节点中包含“ab” . 在空手道,我不知道如何去做 .

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

1 回答

  • 2

    我建议你仔细阅读文档,空手道在这方面有很大的灵活性 . 下面是一些示例,您可以将它们粘贴到 *.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)'
    

相关问题