Contains 不适用于空手道中的每个 JSON 数组

问题描述 投票:0回答:1

尝试以下代码来验证定义的模式是否存在于两个数组中,但不起作用。

* def schema = {"category": "reference","author": "Nigel Rees","title": "Sayings of the Century", "price": 8.95}
* def bookdetails= $api.store.book[*]
* match bookdetails contains schema  

                     
                            
  Json:                     
        {
                "store": {
                    "book": [
                        {
                            "category": "reference",
                            "author": "Nigel Rees",
                            "title": "Sayings of the Century",
                            "price": 8.95
                        }],
                        [{
                            "category": "fiction",
                            "author": "Evelyn Waugh",
                            "title": "Sword of Honour",
                            "price": 12.99
                        },
    {
                            "category": "reference",
                            "author": "Nigel Rees",
                            "title": "Sayings of the Century",
                            "price": 8.95
                        }]}}
karate
1个回答
1
投票

问题中的 JSON 格式不正确,并且不是有效的 JSON。以下示例代码有效:

Feature: Match

Scenario: Match

* def api = 
"""
      {
              "store": {
                  "book": [
                      {
                          "category": "reference",
                          "author": "Nigel Rees",
                          "title": "Sayings of the Century",
                          "price": 8.95
                      },
                      {
                          "category": "fiction",
                          "author": "Evelyn Waugh",
                          "title": "Sword of Honour",
                          "price": 12.99
                      },
                      {
                          "category": "reference",
                          "author": "Nigel Rees",
                          "title": "Sayings of the Century",
                          "price": 8.95
                      }
                      ]
                      }
       }
"""

* def schema = {"category": "reference","author": "Nigel Rees","title": "Sayings of the Century", "price": 8.95}

* def bookdetails = $api.store.book[*]

* match bookdetails contains schema
© www.soinside.com 2019 - 2024. All rights reserved.