Hi :)
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!!
@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 the Accept 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 the Content-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:
Scenario: POST /booking should return 201 status code
Given url 'https://jsonplaceholder.typicode.com/users'
And request
"""
{
"name": "Test User",
"username": "testuser",
"email": "[email protected]",
"address": {
"street": "Has No Name",
"suite": "Apt. 123",
"city": "Electri",
"zipcode": "54321-6789"
}
}
"""
When method post
Then status 201
You can also try setting the Accept to application/xml in your example and see what happens.
@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.
Hi :)
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 200It 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 200This 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!!
Thanks a lot finding solution from last 2 hours you give proper solution
Have you tried to iterate through each of the booking id to call "https://restful-booker.herokuapp.com/booking/:id" after calling "curl -i https://restful-booker.herokuapp.com/booking". I don't know how to do this in Karate. It is not working for me
@dasarih use stack overflow for questions please: https://stackoverflow.com/questions/tagged/karate