Valerian Pereira
Valerian Pereira

Reputation: 727

Validate array within an array case with BDD karate

Using the karate bdd plugin for automated testing cases along with cucumber. Facing a trouble validating an api structure having an array list within an array. How to validate the valuesets array in array structure with bdd karate?

{
    "reqParam": "5bacfbaaa222ed1500f5aa7a",
    "selectionLimit": [],
    "valuesets": [
        [{
                "test": "sample",
                "testB": "sample"
            },
            {
                "test": "sample",
                "testB": "sample"
            },
            {
                "test": "sample",
                "testB": "sample"
            }
        ],
        [{
                "test": "sample",
                "testB": "sample"
            },
            {
                "test": "sample",
                "testB": "sample"
            }
        ]
    ]
}

Here is a piece of the code that I have been working on to accomplish this task.

* def samplePacket = { test: '#string', testB: '#string'}
Scenario: Check the valid params
        Given url API_URL
        Given path 'getParam/apicall'
        And params validParameter
        When method get
        Then status 200
        And match header Content-Type == 'application/json; charset=utf-8'
        #And print response.valuesets[0]
        Then match each response.valuesets == #[] samplePacket

Upvotes: 1

Views: 768

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58058

You've got multiple levels of nested arrays.

* def valueset = { test: '#string', testB: '#string' }
* def setarray = '#[] valueset'
* match response.valuesets == '#[] setarray'

Upvotes: 1

Related Questions