如何在空手道中验证json未命名数组

时间:2018-07-30 13:20:08

标签: karate

我正在尝试验证以下响应,该响应是一个没有数组名称的数组。

[
    {
        "soldTo": "0000100139",
        "productId": "88175838",
        "catalogNumber": "130C-3/4X30FT",
        "manufacturerName": "3M CO. - ELECTRICAL MARKETS DIV.",
        "quantity": "000001",
        "lastPurchaseDate": "Jun 13, 2018 12:00:00 AM",
        "description": "30-feet x 3/4-inch black Scotch&#174 linerless rubber splicing tape.",
        "imageUrl": "https://static.graybar.com/supplierimages/3m_new/130C-1-12X30FT-th.png"
    },
    {
        "soldTo": "0000100139",
        "productId": "25438652",
        "catalogNumber": "312-POUCH",
        "manufacturerName": "3M CO. - ELECTRICAL MARKETS DIV.",
        "quantity": "000011",
        "lastPurchaseDate": "Jul 27, 2018 12:00:00 AM",
        "description": "Yellow Scotchlok&#8482 electrical spring connector in a pouch for 22 to 8 AWG wire.",
        "imageUrl": "https://static.graybar.com/supplierimages/3m_new/312-BAG-th.png"
    },
    {
        "soldTo": "0000100139",
        "productId": "88175944",
        "catalogNumber": "33+SUPER-3/4X66FT",
        "manufacturerName": "3M CO. - ELECTRICAL MARKETS DIV.",
        "quantity": "000001",
        "lastPurchaseDate": "Jun 13, 2018 12:00:00 AM",
        "description": "66-feet x 3/4-inch black Scotch&#174 Super 33+&#8482 vinyl electrical tape.",
        "imageUrl": "https://static.graybar.com/supplierimages/3M_New/MMM_33Super34x66FT-th.png"
    }
]

当我尝试在下面使用匹配每个脚本时都会出错。

And match each response.soldTo == '#string'
    And match each response.productId == '#string'
    And match each response.catalogNumber == '#string'
    And match each response.manufacturerName == '#string'
    And match each response.quantity == '#string'
    And match each response.lastPurchaseDate == '#string'
    And match each response.description == '#string'
    And match each response.imageUrl == '#string

'

错误::com.intuit.karate.exception.KarateException:预期在路径$中找到具有属性['soldTo']的对象,但找到了“ net.minidev.json.JSONArray”。根据JsonProvider,这不是json对象:“ com.jayway.jsonpath.spi.json.JsonSmartJsonProvider”。     在com.intuit.karate.StepDefs.matchNamed(StepDefs.java:540)     在com.intuit.karate.StepDefs.matchEquals(StepDefs.java:526)     在✽。并匹配每个响应。soldTo==“ 0000100139”(先前的订单项/先前的订单项。功能:24)

1 个答案:

答案 0 :(得分:2)

您在JsonPath中犯了一个错误。请更仔细地阅读文档和示例。

* match each response[*].soldTo == '#string'
* match each response[*] contains { productId: '#string', catalogNumber: '#string' }