Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Karate 空手道中包含JSON数组的深度断言_Karate - Fatal编程技术网

Karate 空手道中包含JSON数组的深度断言

Karate 空手道中包含JSON数组的深度断言,karate,Karate,如示例所示,我不担心“年龄”。我知道我可以使用“#忽略”。如果我有很多这样的节点,我必须忽略,还有其他方法吗 我只是在想,它可以像处理JSON对象一样处理JSON数组吗。仅断言指定的节点 错误: Scenario: Given def cat = """ { name: 'Billie', kittens: [ { id: 23, name: 'Bob', age: 35 },

如示例所示,我不担心“年龄”。我知道我可以使用“#忽略”。如果我有很多这样的节点,我必须忽略,还有其他方法吗

我只是在想,它可以像处理JSON对象一样处理JSON数组吗。仅断言指定的节点

错误:

 Scenario: 
    Given def cat =
      """
      {
        name: 'Billie',
        kittens: [
          { id: 23, name: 'Bob', age: 35 },
          { id: 42, name: 'Wild', age: 25 }
        ]
      }
      """
    Then match cat.kittens contains [{ id: 42, name: 'Wild' }, { id: 23, name: 'Bob' }]
编辑:

我尝试了一些建议 但这对我没有帮助。我不是在寻找模式验证,而是在寻找功能验证,其中每个对象的键可能有不同的值

低于一的失败

assert.feature:24 - path: $.kittens[*], actual: [{"id":23,"name":"Bob","age":35},{"id":42,"name":"Wild","age":25}], expected: {id=42, name=Wild}, reason: actual value does not contain expected

这个很好用,但对我没有帮助

  Scenario: 
    Given def cat =
      """
      {
        name: 'Billie',
        kittens: [
          { id: 23, name: 'Bob', age: 35 },
          { id: 42, name: 'Wild', age: 25 }
        ]
      }
      """
      * def expected = [{ id: 42, name: 'Wild' }, { id: 23, name: 'Bob' }]
    Then match cat.kittens contains '#(^expected)'

目前,我正在分别读取数组并使用循环断言它们。

只需添加单词
deep
即可在0.9.6.RC4中使用

  Scenario: 
    Given def cat =
      """
      {
        name: 'Billie',
        kittens: [
          { id: 23, name: 'Bob', age: 35 },
          { id: 42, name: 'Wild', age: 25 }
        ]
      }
      """
      * def expected = { id: 42, name: 'Wild' }
    Then match cat.kittens contains '#(^expected)'

我不明白为什么当我结束你的第一个问题时,链接的答案对你没有帮助。也许我不明白,其他人可以提供更好的答案。

它的工作原理就像一个0.9.6 RC4的冠军。但是我不确定
那么match cat.kittens包含“#”(^expected)”在0.9中如何处理这种情况。5@kishorereddy我不明白你的问题。阅读文档:-如果可能的话,我把它留给其他人来提供更好的答案
Then match cat.kittens contains deep [{ id: 42, name: 'Wild' }, { id: 23, name: 'Bob' }]