ericdriggs
ericdriggs

Reputation: 33

karate request header validation

Would like to be able to assertions to validate that the request header set matches as expected to help validate tests are correctly setting content types supported.

Checked documentation, github issues, stackoverflow, google

Given url myUrl
And params myParams
And headers myHeaders
And header Authorization = babylonAuth
And request historyPostPayload
When method POST
Then status 200

* match requestHeaders.contains({'Content-Type': ''})

Any way to do this now, or is this a feature request?

Upvotes: 1

Views: 2745

Answers (2)

SUWI
SUWI

Reputation: 1

And set headers.Authorization = value Maybe using Scenario Outline please check the API example in my project https://github.com/SuriKarate/LogInUI/tree/main

Upvotes: 0

Peter Thomas
Peter Thomas

Reputation: 58058

Ah, the request header, a very rare need. Yes this is possible by referring to the karate.prevRequest, documented here: https://github.com/intuit/karate#karate-prevrequest

So this should be what you are looking for:

* def contentType = karate.prevRequest.headers['Content-Type'][0]
* match contentType contains 'application/json'

Have a look at this example: encoding.feature

Upvotes: 1

Related Questions