Code 418 is returned instead of 200 if not using "And header Accept = 'application/json'"
See original GitHub issueHi 😃 I am new to API testing and I was testing out Karate to practice API testing but there was a weird thing that happened and I don’t know if it is an issue or a misunderstanding from my side.
I am trying testing against “https://restful-booker.herokuapp.com/” APIs … It is An API playground created by Mark Winteringham for those wanting to learn more about API testing and tools
I added my feature as follows:
Scenario: POST /booking should return 200 status code
Given url 'https://restful-booker.herokuapp.com/booking'
And request read('post_booking_data.json')
When method POST
Then status 200
It didn’t work and returned “418” although when I try the exact thing with postman, the 200 status code is returned successfully. But then after reading another part in Karate documentation, I updated my feature to be as follows:
Scenario: POST /booking should return 200 status code
Given url 'https://restful-booker.herokuapp.com/booking'
And request read('post_booking_data.json')
And header Accept = 'application/json'
When method POST
Then status 200
This just went well and the test ran successfully only after I added “And header Accept = ‘application/json’”
Is there anything that I was doing wrong or I didn’t understand it correctly?
Thanks a lot!!
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top GitHub Comments
@ptrthomas I would like to thank you a lot for your answer. And I think, yes, the API I am trying on is badly designed as you said.
@Aya-Akl I think Karate is working as designed. There are 2 things that are happening. First: while Karate will send the
Content-Type
header automatically depending on the type of the payload, Postman seems to go one step further and set theAccept
header as well.Second: the API here is (at least in my opinion) badly designed. Ideally, the API should assume the intended
Accept
to be same as theContent-Type
if not specified by the user. Here is an example of another API (not created by Mark Winteringham 😉 that works as you would expect:You can also try setting the
Accept
toapplication/xml
in your example and see what happens.