I used Katalon to do this exercise:
I use Restlet-Client for this exercise, also applied on my project.
- Create a Environment Variable to store the value
- Create a Postman collections and save all request below:
β GET room request. And save any roomid of any room.
β POST login. and save the token to env variable
β POST booking. Using the token and roomid above to get the request
Here is my results
- Collection:
- GET method to call against
- POST call against the booking API to make a booking for the room
But the status of the request Collection, Gettoken, POST mothod always return 403 Forbidden
Could you please help to check if I miss any step or the issue come from your API.
Thanks!
I used API Fortress to complete exercise 3. Building upon what I did on exercise 2, I saved the roomid
value returned after creating a room as a dynamic variable and include it in a following request to book that room.
I used a mixture of Postman to explore the API and RestAssured to do the code
All of the exercises/tricks are in this list
I used Postman to complete this exercise.
What I learned
-
409 CONFLICT
The request could not be completed due to a conflict with the current state of the target resource. This code is used in situations where the user might be able to resolve the conflict and resubmit the request. -
Test data can be generated in Postman Pre-request tab. I used it to generate random date. Otherwise POST request returns 409 code.
When I used pm.globals.set("startDate", startDate);
to store generated data, data used in request body did not changefor some reason (e.g Postman always used same key value pair βstartDate: 2022-06-19T09:48:26.469Zβ). When I used postman.setEnvironmentVariable("startDate", startDate);
, Postman used new generated data in each request.
- We can run a sequence of requests using collection menu:
- click 3 dots when collection is selected
- click Run collection
One thing I did not understand is how I can find out the correct format of Header for post request. It should have token in βCookieβ key, but how would I find it? When I view request in Network tab it does not show cookie after clicking Book button on this page Restful-booker-platform demo .
Request Headers
Content-Type: application/json
Cookie: token=1x3TfVxE9KRhnT5z; token=1x3TfVxE9KRhnT5z
User-Agent: PostmanRuntime/7.29.0
Here is Pre-request script to generate date
// generate random dates
function getRndInteger(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
startDate = getRndInteger(10, 20);
endDate = startDate + 2;
console.log(startDate)
console.log(endDate);
startDate = "2022-06-"+ startDate.toString()+"T09:48:26.469Z";
endDate = "2022-06-"+ endDate.toString()+"T09:48:26.469Z";
console.log("startDate: "+startDate);
console.log("endDate: "+endDate);
postman.setEnvironmentVariable("startDate", startDate);
postman.setEnvironmentVariable("endDate", endDate);
Links:
Here is example of the test written usingTavern, YAML and Python. You can find my repository on GitHub.
# test_basics.tavern.yaml
# Saving data from response using external functions
test_name: Saving data from response using external functions ex11
stages:
- name: Validate status code 200
request:
url: http://www.recipepuppy.com/api/
method: GET
json:
i: avocado
q: kale
p: 1
response:
json:
title: "Recipe Puppy"
save:
$ext:
function: utils:save_data
json:
test_ingredients: results[0].ingredients
- name: Validate saved data
request:
url: http://www.recipepuppy.com/api/
method: GET
json:
i: avocado
q: kale
p: 1
response:
status_code: 200
json:
results:
- title: "{test_title}"
ingredients: "{test_ingredients}"
#In this case, both `{test_title}` and `{test_ingredients}` are available for use
#in later requests
# utils.py
def save_data(response):
return Box({"test_title": response.json()["results"][0]["title"]})