Begineer
Begineer

Reputation: 43

Karate scenerio creation for testing error message returned in JSON format

I have one get operation which returns below format while fetching invalid data

{
    "exchangeReturnCod": "ERROR",
    "errors": [
        {
            "code": "XXX",
            "severity": "ERROR",
            "source": "Application with id APPLICATIONNOTEXIST doesn't exist.",
        }
    ]
}

I want to match this error message in feature file. I have used below syntaxes but none is working.

And match response.feedbacks errors {source:"Application with id APPLICATIONNOTEXIST doesn't exist."}

Could you please guide what i am doing wrong here?

Upvotes: 2

Views: 560

Answers (1)

Babu Sekaran
Babu Sekaran

Reputation: 4239

This should work,

* def expected = {source:"Application with id APPLICATIONNOTEXIST doesn't exist."}
* match $response.errors[*].source contains expected.source

Since your response returns an array of errors this will validate atleast one error should have the expected source.

Upvotes: 1

Related Questions