Hey Duong,
You need to set the token as a cookie in order to do a POST, the cookie you acquired in step one.
That is the problem here I think.
Regards
Hey Duong,
You need to set the token as a cookie in order to do a POST, the cookie you acquired in step one.
That is the problem here I think.
Regards
Hi @friendlytester,
You are correct. After setting the token as a cookie I could get status code 200
I just suggest you update the line
Extract the token and store it
to
Extract the token and store it as a cookie
So the newbie members like me will not disturb you
Thank you for your quick support.
Yes I used postman and able to parameterise the request run time by setting the token and roomid as env variables. And request are successful.
But if we use Same checkin and checkout time (time&date) then the request will give 409 (Conflict).
We need to handle timestamp in a generic way.
Let try to use Chakram API Testing Framework and Mocha - I have finished this challenges using my own API
Step 1: Get full candidates list, this API will return a list of candidates in the system
Step 2: From the response in step 1, try to get the first candidateโs id and then pass it as the query string for step 3
Step 3: Call API to get specific candidate by candidate id
How do you extract the token and store it as a cookie in Postman? Iโm new to this and have tried to Google it but canโt find the information.
Used advanced rest client
Hi @helena, you can use environment variables or global variable to parameterize the the request. For below example, I use โjson()โ method to extract the token then set it to an environment variale โeTokenโ, after running test, we will see an โeTokenโ variable would be created:
Hope it might help you
Thank you! Will try this at once
I use my own framework to complete the exercise 3 with the steps below:
My exercise 3 with Katalon is:
I use Postman for this exercise.
My Solution:
Here is my result
Collection:
Post method to login and store the token to env variable
Get method to get room and story a room_id to env variable
Post method to booking
Here is the result when running the collection
I will do this exercise again on Katalon when I have free time.
I use Restlet-Client for this exercise, also applied on my project.
Here is my results
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.
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"]})