空手道中的复杂模式验证

Complex schema validation in Karate

我正在尝试使用空手道验证响应模式,但遇到数组问题。 附上回复和功能以及我的 schema.json.

回应-

{
"page": 1,
"per_page": 6,
"total": 12,
"total_pages": 2,
"data": [
    
    {
        "id": 3,
        "email": "emma.wong@reqres.in",
        "first_name": "Emma",
        "last_name": "Wong",
        "avatar": "https://reqres.in/img/faces/3-image.jpg"
    },
    {
        "id": 4,
        "email": "eve.holt@reqres.in",
        "first_name": "Eve",
        "last_name": "Holt",
        "avatar": "https://reqres.in/img/faces/4-image.jpg"
    },
    {
        "id": 5,
        "email": "charles.morris@reqres.in",
        "first_name": "Charles",
        "last_name": "Morris",
        "avatar": "https://reqres.in/img/faces/5-image.jpg"
    },
    {
        "id": 6,
        "email": "tracey.ramos@reqres.in",
        "first_name": "Tracey",
        "last_name": "Ramos",
        "avatar": "https://reqres.in/img/faces/6-image.jpg"
    }
],
"support": {
    "url": "https://reqres.in/#support-heading",
    "text": "To keep ReqRes free, contributions towards server costs are appreciated!"
}

}

 Scenario: Get all Users and validate schema
    Given url getUrl
    When method Get
    Then status 200
    And print response
    Then match response == '#object'
    * string jsonSchemaExpected = read('file:src/test/resources/features/sample/responseSchema.json')
    And print response.data.length 
    And match response == jsonSchemaExpected

responseSchema.json

{ "page": "#number", "per_page": "#number", "total": "#number", "total_pages": "#number", "data": "#[] #object", "support": "#object" }

我唯一的观察是,如果您转换为字符串,您将无法进行任何匹配。

而不是 * string jsonSchemaExpected* def jsonSchemaExpected.